Esempio n. 1
0
    def test_schedule(self):
        """
        Test schedules of Chinese stations reported by Cristina (XINGREN , Kuqa ), where schedules are duplicated
        """

        year = 2019
        month = 3
        day = 25
        hour = 0

        mydate = datetime.datetime(year, month, day, hour)

        lower_boundary = mydate - timedelta(hours=3)
        upper_boundary = mydate + timedelta(hours=3)

        s1 = Schedule()
        s1.hour_from = 0
        s1.min_from = 0
        s1.hour_to = 21
        s1.min_to = 59
        s1.interval = 60 * 60 * 3

        s2 = Schedule()
        s2.hour_from = 0
        s2.min_from = 0
        s2.hour_to = 21
        s2.min_to = 59
        s2.interval = 60 * 60 * 3

        r = number_expected([s1, s2], lower_boundary, upper_boundary)

        self.assertEqual(r, 2)
Esempio n. 2
0
    def test_schedule(self):
        """
        Test schedules of stations with same starting hour
        """

        year = 2019
        month = 3
        day = 25
        hour = 0

        mydate = datetime.datetime(year, month, day, hour)

        lower_boundary = mydate - timedelta(hours=3)
        upper_boundary = mydate + timedelta(hours=3)

        s = Schedule()
        s.hour_from = 3
        s.min_from = 0
        s.hour_to = 3
        s.min_to = 59
        s.interval = 60 * 60 * 6

        r = number_expected([
            s,
        ], lower_boundary, upper_boundary)

        self.assertEqual(r, 0)
Esempio n. 3
0
    def test_schedule(self):
        """
        Test upper boundary higher than upper boundary
        """

        year = 2019
        month = 3
        day = 25
        hour = 0

        mydate = datetime.datetime(year, month, day, hour)

        lower_boundary = mydate - timedelta(hours=3)
        upper_boundary = mydate + timedelta(hours=3)

        s = Schedule()
        s.hour_from = 22
        s.min_from = 0
        s.hour_to = 21
        s.min_to = 59
        s.interval = 60 * 60

        r = number_expected([
            s,
        ], lower_boundary, upper_boundary)

        self.assertEqual(r, 6)
Esempio n. 4
0
    def test_schedule(self):
        """
        Test the schedule
        """

        year = 2019
        month = 3
        day = 25
        hour = 0

        mydate = datetime.datetime(year, month, day, hour)

        lower_boundary = mydate - timedelta(hours=3)
        upper_boundary = mydate + timedelta(hours=3)

        s = Schedule()  # default schedule has 6h observations

        r = number_expected([s], lower_boundary, upper_boundary)

        self.assertEqual(r, 1)
Esempio n. 5
0
    def test_schedule(self):
        """
        Test three overlapping schedules with 30min, 45min and 1h
        """

        year = 2019
        month = 3
        day = 25
        hour = 0

        mydate = datetime.datetime(year, month, day, hour)

        lower_boundary = mydate - timedelta(hours=3)
        upper_boundary = mydate + timedelta(hours=3)

        s1 = Schedule()
        s1.hour_from = 0
        s1.min_from = 30
        s1.hour_to = 23
        s1.min_to = 30
        s1.interval = 60 * 30

        s2 = Schedule()
        s2.hour_from = 0
        s2.min_from = 30
        s2.hour_to = 23
        s2.min_to = 30
        s2.interval = 60 * 60

        s3 = Schedule()
        s3.hour_from = 22
        s3.min_from = 0
        s3.hour_to = 23
        s3.min_to = 30
        s3.interval = 60 * 5

        r = number_expected([s1, s2, s3], lower_boundary, upper_boundary)

        self.assertEqual(r, 25)
Esempio n. 6
0
    def test_schedule(self):
        """
        Test 30 min vs 45min overlap test
        """

        year = 2019
        month = 3
        day = 25
        hour = 0

        mydate = datetime.datetime(year, month, day, hour)

        lower_boundary = mydate - timedelta(hours=3)
        upper_boundary = mydate + timedelta(hours=3)

        s4 = Schedule()
        s4.interval = 60 * 30

        s5 = Schedule()
        s5.interval = 60 * 45

        r = number_expected([s4, s5], lower_boundary, upper_boundary)

        self.assertEqual(r, 16)
Esempio n. 7
0
    def test_schedule(self):
        """
        Test for the bug identified by ECMWF where the reporting interval does not fit the interval between upper and lower boundary
        """

        year = 2019
        month = 3
        day = 25
        hour = 0

        mydate = datetime.datetime(year, month, day, hour)

        lower_boundary = mydate - timedelta(hours=3)
        upper_boundary = mydate + timedelta(hours=3)

        s4 = Schedule()
        s4.interval = 60 * 30

        s5 = Schedule()
        s5.interval = 60 * 45

        r = number_expected([s4, s5], lower_boundary, upper_boundary)

        self.assertEqual(r, 16)
Esempio n. 8
0
def nr_expected(wigos_id):
    period = request.args.get("date", None)
    variables = request.args.get("variables", None)

    if not len(wigos_id.split("-")) == 4:
        abort(400, "wigos id {} not in right format".format(wigos_id))

    if not period:
        abort(400, "need to supply period parameter")

    try:
        period = datetime.strptime(period, "%Y-%m-%d")
    except:
        abort(400, "date format error")

    variables = variables.split(',') if variables else []
    logger.info("variables {}".format(variables))
    try:
        variables = list(variables_map.keys()) if 'ALL' in variables else [
            int(v) for v in variables
        ]
    except:
        abort(400, "variables need to be specified as intergers")

    # get schedules
    mydate = period  # the date and hour for which we calculate the number of expected

    # +- 3h interval around the date
    lower_boundary = mydate - timedelta(hours=3)
    upper_boundary = mydate + timedelta(hours=3)

    logger.info(
        "checking number expected for station {} and variables {} interval {} to {}"
        .format(wigos_id, variables, lower_boundary, upper_boundary))

    try:
        infos = getSchedules(wigos_id, variables)
        observations = infos["observations"]
        name = infos["name"]
    except Exception as e:
        abort(500, str(e))

    response = {"wigos_id": wigos_id, "name": name, "variables": []}

    for var_id, info in observations.items():
        schedules = info["schedules"]
        name = info["variableName"]

        if len(schedules) == 0:
            continue

        e = {}
        for sh in [0, 6, 12, 18]:
            e["h{}".format(sh)] = number_expected(
                schedules, lower_boundary + timedelta(hours=sh),
                upper_boundary + timedelta(hours=sh))

        response["variables"].append({
            'var_id': var_id,
            'variable': name,
            'nr_expected': e,
            'schedules': [str(s) for s in schedules]
        })

        #print("variable: {} expected: {} for schedules {}".format(var_mapping[var_id],e,  ",".join([ str(s) for s in schedules ])  ))

    # Return the response in json format
    return jsonify(response)