class FixtureReportResult(Document, QueryMixin): domain = StringProperty() location_id = StringProperty() start_date = DateProperty() end_date = DateProperty() report_slug = StringProperty() rows = DictProperty() name = StringProperty() class Meta(object): app_label = "m4change" @classmethod def by_composite_key(cls, domain, location_id, start_date, end_date, report_slug): try: return cls.view("m4change/fixture_by_composite_key", key=[domain, location_id, start_date, end_date, report_slug], include_docs=True).one(except_all=True) except (NoResultFound, ResourceNotFound, MultipleResultsFound): return None @classmethod def all_by_composite_key(cls, domain, location_id, start_date, end_date, report_slug): return cls.view("m4change/fixture_by_composite_key", startkey=[domain, location_id, start_date, end_date, report_slug], endkey=[domain, location_id, start_date, end_date, report_slug], include_docs=True).all() @classmethod def by_domain(cls, domain): return cls.view("m4change/fixture_by_composite_key", startkey=[domain], endkey=[domain, {}], include_docs=True).all() @classmethod def get_report_results_by_key(cls, domain, location_id, start_date, end_date): return cls.view("m4change/fixture_by_composite_key", startkey=[domain, location_id, start_date, end_date], endkey=[domain, location_id, start_date, end_date, {}], include_docs=True).all() @classmethod def _validate_params(cls, params): for param in params: if param is None or len(param) == 0: return False return True @classmethod def save_result(cls, domain, location_id, start_date, end_date, report_slug, rows, name): if not cls._validate_params([domain, location_id, report_slug]) \ or not isinstance(rows, dict) or len(rows) == 0 \ or not isinstance(start_date, date) or not isinstance(end_date, date): return FixtureReportResult(domain=domain, location_id=location_id, start_date=start_date, end_date=end_date, report_slug=report_slug, rows=rows, name=name).save()
class CObservationAddendum(OldDocument): observed_date = DateProperty() art_observations = SchemaListProperty(CObservation) nonart_observations = SchemaListProperty(CObservation) created_by = StringProperty() created_date = OldDateTimeProperty() notes = StringProperty() # placeholder if need be class Meta: app_label = 'pact'
class LegacyWeeklyReport(Document): """ This doc stores the aggregate weekly results per site. Example: domain: 'mikesproject', site: 'Pennsylvania State Elementary School', week_end_date: Saturday Sept 28, 2013, site_strategy: [3, -1, 0, 4, 2], site_game: [2, 4, 3, 1, 0], individual: { 'mikeo': { 'strategy': [2, 4, 0, 1, 3], 'game': [1, 2, 4, 1, 0], 'weekly_totals': [ ['Sept 9', 3], ['Sept 16', 2], ['Sept 23', 5], # current week ], }, }, 'weekly_totals': [ ['Sept 9', 11], ['Sept 16', 6], ['Sept 23', 9], # current week ], Where each week is a 5 element list. 0 indicates that no strategies/games were recorded, -1 indicates an off day (nothing recorded, but that's okay). """ domain = StringProperty() site = StringProperty() week_end_date = DateProperty() site_strategy = ListProperty() site_game = ListProperty() individual = DictProperty() weekly_totals = ListProperty() @classmethod def by_site(cls, site, date=None): if isinstance(site, Group): site = site.name if date is None: # get the most recent saturday (isoweekday==6) days = [6, 7, 1, 2, 3, 4, 5] today = datetime.date.today() date = today - datetime.timedelta( days=days.index(today.isoweekday()) ) report = cls.view( 'penn_state/smiley_weekly_reports', key=[DOMAIN, site, str(date)], reduce=False, include_docs=True, ).first() return report @classmethod def by_user(cls, user, date=None): # Users should only have one group, and it should be a report group groups = Group.by_user(user).all() # if len(groups) != 1 or not groups[0].reporting: if len(groups) == 0 or not groups[0].reporting: return site = groups[0].name return cls.by_site(site, date)
class VscanUpload(Document): scanner_serial = StringProperty() scan_id = StringProperty() date = DateProperty()