class SubmissionFile(MongoModel): user_id = fields.ReferenceField(User, required=True) course_id = fields.ReferenceField(Course, required=True) homework_id = fields.ReferenceField(Homework, required=True) file_name = fields.CharField(required=True, blank=True, default='') file_type = fields.CharField(required=True, blank=True, default='') file_id = fields.FileField(required=True) create_at = fields.DateTimeField(required=True, default=get_timestamp) class Meta: indexes = [ pymongo.IndexModel([('course_id', pymongo.ASCENDING)]), pymongo.IndexModel([('homework_id', pymongo.ASCENDING)]) ]
class StopWords(CreatedUpdated, MongoModel): user = fields.ReferenceField(User, required=True) filename = fields.CharField(required=True) display_title = fields.CharField(required=True) description = fields.CharField(required=True) file = fields.FileField(required=True) created = fields.DateTimeField() updated = fields.DateTimeField() def delete(self): if self.file: self.file.delete() super(StopWords, self).delete()
class RunningRace(EmbeddedMongoModel): name = fields.CharField(verbose_name='Race Name', required=True) distance_name = fields.CharField(verbose_name='Distance Description', choices=('1 mile', '5k', '10k', '15k', 'half marathon', 'marathon'), required=True) distance_m = fields.FloatField(verbose_name='Distance [m]', required=True) chip_time_s = fields.FloatField(verbose_name='Chip Time [s]', mongo_name='ct_s', required=True) gun_time_s = fields.FloatField(verbose_name='Gun Time [s]', mongo_name='gt_s', required=True) splits_s = fields.DictField() overall_place = fields.IntegerField(verbose_name='Overall Place', required=True) overall_field_size = fields.IntegerField( verbose_name='Size of Overall Field', required=True) detailed_place = fields.DictField() # photos = fields.ListField(fields.ImageField(), default=[]) supporting_files = fields.ListField(fields.FileField(), default=[]) @property def distance(self): return self.distance_m * ureg.meter @property def chip_time(self): return self.chip_time_s * ureg.second @property def gun_time(self): return self.gun_time_s * ureg.second @property def splits(self): return { split_name: split_time_s * uref.second for split_name, split_time_s in self.splits_s.items() } @property def overall_place_percent(self): return round(100 * self.overall_place / float(self.overall_field_size), 1)
class DataSource(CreatedUpdated, MongoModel): user = fields.ReferenceField(User, required=True) filename = fields.CharField(required=True, validators=[has_extension('txt', 'csv')]) file_format = fields.CharField(required=True, default="newsgac", validators=[lambda x: x in ['csv', 'newsgac']]) csv_label_field = fields.CharField(required=False, default="label") csv_text_field = fields.CharField(required=False, default="text") labels = fields.ListField(fields.CharField(), default=[]) display_title = fields.CharField(required=True) description = fields.CharField(required=True) file = fields.FileField(required=True) training_purpose = fields.BooleanField(required=True, default=False) articles = fields.ListField(fields.ReferenceField(Article)) task = fields.EmbeddedDocumentField(TrackedTask, default=TrackedTask()) created = fields.DateTimeField() updated = fields.DateTimeField() def delete(self): if self.file: self.file.delete() from newsgac.ace import ACE for ace in ACE.objects.raw({'data_source': self.pk}): ace.delete() super(DataSource, self).delete() def status(self): if self.task: return self.task.status else: return 'UNKNOWN' def full_clean(self, exclude=None): super(DataSource, self).full_clean(exclude) if not self._id: # ensure unique display_title try: DataSource.objects.get({'display_title': self.display_title}) except DoesNotExist as e: return raise ValidationError('Display title exists') def __repr__(self): return '[DataSource id: {0}]'.format(self._id)
class Activity(MongoModel): start_time = fields.DateTimeField(verbose_name='Start Time', mongo_name='start_dt') total_time_s = fields.FloatField(verbose_name='Total Time [s]', mongo_name='time_s') total_distance_m = fields.FloatField(verbose_name='Total Distance [m]', mongo_name='distance_m') calories_cal = fields.IntegerField(verbose_name='Calories', mongo_name='cal') avg_speed_m_s = fields.FloatField(verbose_name='Average Speed [m/s]') max_speed_m_s = fields.FloatField(verbose_name='Maximum Speed [m/s]') total_ascent_m = fields.IntegerField(verbose_name='Total Ascent [m]', mongo_name='ascent_m') total_descent_m = fields.IntegerField(verbose_name='Total Descent [m]', mongo_name='descent_m') avg_heart_rate_bpm = fields.IntegerField( verbose_name='Average Heart Rate [bpm]', mongo_name='avg_hr_bpm') max_heart_rate_bpm = fields.IntegerField( verbose_name='Maximum Heart Rate [bpm]', mongo_name='max_hr_bpm') aerobic_training_effect = fields.FloatField( verbose_name='Aerobic Training Effect', mongo_name='aerobic_t_e') anaerobic_training_effect = fields.FloatField( verbose_name='Anaerobic Training Effect', mongo_name='anaerobic_t_e') avg_temperature_c = fields.IntegerField( verbose_name='Average Temperature [C]', mongo_name='avg_temp_c') max_temperature_c = fields.IntegerField( verbose_name='Maximum Temperature [C]', mongo_name='max_temp_c') start_body_weight_measurment = fields.ReferenceField(BodyWeight) end_body_weight_measurment = fields.ReferenceField(BodyWeight) device = fields.ReferenceField(Device) start_location = fields.ReferenceField(Location) source_file = fields.FileField() commute = fields.BooleanField(default=False) class Meta: connection_alias = 'activity-connection' collection_name = 'data' @property def total_time(self): return self.total_time_s * ureg.second @property def total_distance(self): return self.total_distance_m * ureg.meter @property def calories(self): return self.calories_cal * ureg.calorie @property def avg_speed(self): return self.avg_speed_m_s * ureg.meter / ureg.second @property def max_speed(self): return self.max_speed_m_s * ureg.meter / ureg.second @property def total_ascent(self): return self.total_ascent_m * ureg.meter @property def total_descent(self): return self.total_descent_m * ureg.meter @property def avg_temperature(self): return ureg.Quantity(self.avg_temperature_c, ureg.degC) @property def max_temperature(self): return ureg.Quantity(self.max_temperature_c, ureg.degC) @property def source_file_as_fit(self): self.source_file.open() fit_file = FitFile(b''.join(self.source_file.file.chunks())) self.source_file.close() return fit_file @property def start_body_weight(self): return self.start_body_weight_measurment.value @property def end_body_weight(self): return self.end_body_weight_measurment.value @property def avg_body_weight(self): return 0.5 * (self.start_body_weight + self.end_body_weight)