Example #1
0
def get_reports(status='all', l=10):
    if status == 'all':
        return Report.objects.order_by('-date_created').limit(l)
    elif status in ["new", "decided"]:
        return Report.objects(status=status).order_by('-date_created').limit(l)
    else:
        return []
Example #2
0
 def get(self, period):
     """
     Returns a list of measurements given a time-period range
     """
     report = Report.objects(period=period).first()
     if report is not None:
         return report.to_dict(), 200
     self.abort_with_http_code_error(404, f'Report con period={period} was not found')
Example #3
0
 def get(self, period):
     try:
         report = Report.objects(period=period).first()
         if report is not None:
             return report.to_dict(), 200
         abort(404, message=f'Report for period {period} was not found')
     except NotFound as e:
         app.logger.error(e)
         raise e
     except Exception as e:
         app.logger.error(e)
         abort(500, message=str(e))
    def get_users_group_status(self, group):
        report = Report.objects(date=datetime.now().date()).first()

        here = []
        not_here = []
        not_specified = []

        for item in group.items:
            status = self.user_statuses(report, item.id)
            if status is None:
                not_specified.append(item.name)
            elif status.state == "Here":
                here.append(item.name)
            elif status.state == "Not Here":
                not_here.append((item.name, status.reason))

        return here, not_here, not_specified
Example #5
0
    def get_users_status(self):
        report = Report.objects(date=datetime.now().date()).first()
        users = User.objects.all()

        here = []
        not_here = []
        not_specified = []

        for user in users:
            status = self.user_statuses(report, user.id)
            if status is None:
                not_specified.append(user.name)
            elif status.state == "Here":
                here.append(user.name)
            elif status.state == "Not Here":
                not_here.append((user.name, status.reason))

        return here, not_here, not_specified
Example #6
0
def main():
    # Get current day - 1
    logger.info('Calculating yesterday\'s day')
    yesterday = get_yesterday_date()
    # Get yesterday's measurement
    logger.info(f'Getting measurement for {get_formatted_date(yesterday)}')
    measurement = Measurement.objects(
        created=get_formatted_date(yesterday)).first()
    if measurement is None:
        raise Exception(
            f'Measurement for date={get_formatted_date(yesterday)} was not found'
        )

    # Compute the period for that measurment
    logger.info(f'Calculating period for {get_formatted_date(yesterday)}')
    period = get_period(yesterday)
    # Get the report by period
    logger.info(f'Getting report for {period}')
    report = Report.objects(period=period).first()
    if report is None:
        logger.info(f'Report not found, creating a new report for {period}')
        report = Report(
            period=period,
            values=[],
            user=User.objects(email='*****@*****.**').first())
        report.save()

    logger.info(
        f'Adding a new measurement for {measurement.created} in period {period}'
    )
    report_item = MeasurementValue(sys=measurement.sys,
                                   dia=measurement.dia,
                                   pul=measurement.pul,
                                   date=measurement.created,
                                   ok=measurement.is_ok())
    report.values.append(report_item)
    report.save()
    logger.info('Done')
Example #7
0
def meta(id):
    email = jwt.decode(id, jwt_scecret)['email']
    user = User.objects.get(email=email)
    reports = Report.objects(user=user.publickey)
    u = {}
    for report in reports:
        for d in report.disease:
            if d in u:
                u[d] += 1
            else:
                u[d] = 1
    meta = {}
    meta['disease'] = u
    u = {}
    for report in reports:
        for d in report.drugs:
            if d in u:
                u[d] += 1
            else:
                u[d] = 1
    meta['drugs'] = u

    return(meta)
    def _callback(self, bot, update, user):
        now = datetime.now().date()
        formated_day = now.strftime(self.DATE_FORMAT)
        user_id = update.message.chat.id

        report = Report.objects(date=now).first()

        user_statuses = self.user_statuses(report, user_id)

        if len(user_statuses) == 0:
            self.logger.debug("status not exist")
            self.status_message_response(update=update,
                                         date=formated_day,
                                         state=NOT_HERE,
                                         reason="Not Specified",
                                         user=user)
            return

        status = user_statuses[-1]
        self.status_message_response(update=update,
                                     date=formated_day,
                                     state=status.state,
                                     reason=status.reason,
                                     user=user)
Example #9
0
def update_report(_id, status):
    report = Report.objects(pk=ObjectId(_id))
    return report.update(status=status)