Ejemplo n.º 1
0
 def handle_endtag(self, tag):
     popped_ok = False
     while self.tag_stack:
         if tag == self.tag_stack.pop():
             popped_ok = True
             break
     if not popped_ok:
         raise HTMLParseError("Unmatched end tag: %s" % tag)
     if tag == "td" and self.tables_instack() == 2 and self.in_main_table_row:
         if self.read_row_text:
             self.read_row_text = False
             self.row_texts.append(" ".join(self.row_text))
             self.row_text = []
     elif tag == "tr" and self.tables_instack()==2 and self.in_main_table_row:
         self.in_main_table_row = False
         if self.this_row_ratings:
             for region, rating_val in zip(self.last_row_texts, self.row_texts):
                 rating=PollutionRating(rating_val)
                 if "Sydney" in region:
                     add_statistic_list_item("air_pollution", "syd:rt", "regions", rating.display(), self.sort_order,
                                 label=region, traffic_light_code=rating.tlc())
                     add_statistic_list_item("air_pollution", "syd:rt", "region_1", rating.display(), self.sort_order,
                                 label=region, traffic_light_code=rating.tlc())
                     if rating > self.sydney_worst:
                         self.sydney_worst = rating
                 else:
                     add_statistic_list_item("air_pollution", "nsw:rt", "regions", rating.display(), self.sort_order,
                                 label=region, traffic_light_code=rating.tlc())
                     add_statistic_list_item("air_pollution", "nsw:rt", "region_1", rating.display(), self.sort_order,
                                 label=region, traffic_light_code=rating.tlc())
                 self.sort_order += 10
     elif tag == "table" and self.tables_instack() == 1 and self.level_2_table_number == 1:
         add_statistic_list_item("air_pollution", "nsw:rt", "regions", self.sydney_worst.display(), 10,
                     label="Sydney", traffic_light_code=self.sydney_worst.tlc())
         add_statistic_list_item("air_pollution", "nsw:rt", "region_1", self.sydney_worst.display(), 10,
                     label="Sydney", traffic_light_code=self.sydney_worst.tlc())
     elif tag == "table" and self.tables_instack() == 1 and self.level_2_table_number == 2:
         self.in_syd_forecast_table = False
     elif tag == "td" and self.in_syd_forecast_table:
         if self.row_text:
             val = " ".join(self.row_text)
             try:
                 rating = PollutionRating(val)
                 set_statistic_data("air_pollution", "nsw:rt", "sydney_forecast", rating.display(),
                                         traffic_light_code = rating.tlc())
                 set_statistic_data("air_pollution", "syd:rt", "sydney_forecast", rating.display(),
                                         traffic_light_code = rating.tlc())
             except HTMLParseError:
                 pass
             self.row_text = []
Ejemplo n.º 2
0
def update_widget(graph, count_dataset, duration_dataset, 
                count_statistic, duration_statistic, time_format,
                bad_duration, poor_duration):
    count_stat = get_statistic(graph.tile.widget.url, 
                        graph.tile.widget.actual_location.url, 
                        graph.tile.widget.actual_frequency.url,
                        count_statistic)
    duration_stat = get_statistic(graph.tile.widget.url, 
                        graph.tile.widget.actual_location.url,
                        graph.tile.widget.actual_frequency.url,
                        duration_statistic)
    last_count_data = graph.get_last_datum(count_dataset)
    last_duration_data = graph.get_last_datum(duration_dataset)
    # count
    if time_format == TF_QUARTER_HOUR_RANGE:
        period = 15
    else:
        period  = 60
    oldval = count_stat.get_data()
    if oldval is None:
        trend = 0
    elif oldval.value() == last_count_data.value:
        trend = 0
    elif oldval.value() < last_count_data.value:
        trend = 1
    else:
        trend = -1
    # tlc = get_traffic_light_code(count_stat, "good")
    tlc = None
    if not oldval or trend != 0:
        set_statistic_data(graph.tile.widget.url, 
                        graph.tile.widget.actual_location.url,
                        graph.tile.widget.actual_frequency.url,
                        count_statistic, last_count_data.value / decimal.Decimal(period),
                        traffic_light_code=tlc, trend=trend)
    # duration
    oldval = duration_stat.get_data()
    if oldval:
        oldval = oldval.value()

    newval_min = int(last_duration_data.value)
    newval_sec = int((last_duration_data.value - newval_min) * 60)
    newval = "%02d:%02d" % (newval_min, newval_sec)
    if oldval is None:
        trend = 0
    elif oldval < newval:
        trend = 1
    else:
        trend = -1
# if newval > bad_duration:
#    tlc = get_traffic_light_code(count_stat, "bad")
# elif newval > poor_duration:
#    tlc = get_traffic_light_code(count_stat, "poor")
# else:
#    tlc = get_traffic_light_code(count_stat, "good")
    tlc = None
    if not oldval or trend != 0:
        set_statistic_data(graph.tile.widget.url, 
                        graph.tile.widget.actual_location.url,
                        graph.tile.widget.actual_frequency.url,
                        duration_statistic, newval,
                        traffic_light_code=tlc, trend=trend)
    return
Ejemplo n.º 3
0
def update_widget(
    graph,
    count_dataset,
    duration_dataset,
    count_statistic,
    duration_statistic,
    time_format,
    bad_duration,
    poor_duration,
):
    count_stat = get_statistic(
        graph.tile.widget.url,
        graph.tile.widget.actual_location.url,
        graph.tile.widget.actual_frequency.url,
        count_statistic,
    )
    duration_stat = get_statistic(
        graph.tile.widget.url,
        graph.tile.widget.actual_location.url,
        graph.tile.widget.actual_frequency.url,
        duration_statistic,
    )
    last_count_data = graph.get_last_datum(count_dataset)
    last_duration_data = graph.get_last_datum(duration_dataset)
    # count
    if time_format == TF_QUARTER_HOUR_RANGE:
        period = 15
    else:
        period = 60
    oldval = count_stat.get_data()
    if oldval is None:
        trend = 0
    elif oldval.value() == last_count_data.value:
        trend = 0
    elif oldval.value() < last_count_data.value:
        trend = 1
    else:
        trend = -1
    # tlc = get_traffic_light_code(count_stat, "good")
    tlc = None
    if not oldval or trend != 0:
        set_statistic_data(
            graph.tile.widget.url,
            graph.tile.widget.actual_location.url,
            graph.tile.widget.actual_frequency.url,
            count_statistic,
            last_count_data.value / decimal.Decimal(period),
            traffic_light_code=tlc,
            trend=trend,
        )
    # duration
    oldval = duration_stat.get_data()
    if oldval:
        oldval = oldval.value()

    newval_min = int(last_duration_data.value)
    newval_sec = int((last_duration_data.value - newval_min) * 60)
    newval = "%02d:%02d" % (newval_min, newval_sec)
    if oldval is None:
        trend = 0
    elif oldval < newval:
        trend = 1
    else:
        trend = -1
    # if newval > bad_duration:
    #    tlc = get_traffic_light_code(count_stat, "bad")
    # elif newval > poor_duration:
    #    tlc = get_traffic_light_code(count_stat, "poor")
    # else:
    #    tlc = get_traffic_light_code(count_stat, "good")
    tlc = None
    if not oldval or trend != 0:
        set_statistic_data(
            graph.tile.widget.url,
            graph.tile.widget.actual_location.url,
            graph.tile.widget.actual_frequency.url,
            duration_statistic,
            newval,
            traffic_light_code=tlc,
            trend=trend,
        )
    return
Ejemplo n.º 4
0
 def handle_endtag(self, tag):
     popped_ok = False
     while self.tag_stack:
         if tag == self.tag_stack.pop():
             popped_ok = True
             break
     if not popped_ok:
         raise HTMLParseError("Unmatched end tag: %s" % tag)
     if tag == "td" and self.tables_instack(
     ) == 2 and self.in_main_table_row:
         if self.read_row_text:
             self.read_row_text = False
             self.row_texts.append(" ".join(self.row_text))
             self.row_text = []
     elif tag == "tr" and self.tables_instack(
     ) == 2 and self.in_main_table_row:
         self.in_main_table_row = False
         if self.this_row_ratings:
             for region, rating_val in zip(self.last_row_texts,
                                           self.row_texts):
                 rating = PollutionRating(rating_val)
                 if "Sydney" in region:
                     add_statistic_list_item(
                         "air_pollution",
                         "syd:rt",
                         "regions",
                         rating.display(),
                         self.sort_order,
                         label=region,
                         traffic_light_code=rating.tlc())
                     add_statistic_list_item(
                         "air_pollution",
                         "syd:rt",
                         "region_1",
                         rating.display(),
                         self.sort_order,
                         label=region,
                         traffic_light_code=rating.tlc())
                     if rating > self.sydney_worst:
                         self.sydney_worst = rating
                 else:
                     add_statistic_list_item(
                         "air_pollution",
                         "nsw:rt",
                         "regions",
                         rating.display(),
                         self.sort_order,
                         label=region,
                         traffic_light_code=rating.tlc())
                     add_statistic_list_item(
                         "air_pollution",
                         "nsw:rt",
                         "region_1",
                         rating.display(),
                         self.sort_order,
                         label=region,
                         traffic_light_code=rating.tlc())
                 self.sort_order += 10
     elif tag == "table" and self.tables_instack(
     ) == 1 and self.level_2_table_number == 1:
         add_statistic_list_item("air_pollution",
                                 "nsw:rt",
                                 "regions",
                                 self.sydney_worst.display(),
                                 10,
                                 label="Sydney",
                                 traffic_light_code=self.sydney_worst.tlc())
         add_statistic_list_item("air_pollution",
                                 "nsw:rt",
                                 "region_1",
                                 self.sydney_worst.display(),
                                 10,
                                 label="Sydney",
                                 traffic_light_code=self.sydney_worst.tlc())
     elif tag == "table" and self.tables_instack(
     ) == 1 and self.level_2_table_number == 2:
         self.in_syd_forecast_table = False
     elif tag == "td" and self.in_syd_forecast_table:
         if self.row_text:
             val = " ".join(self.row_text)
             try:
                 rating = PollutionRating(val)
                 set_statistic_data("air_pollution",
                                    "nsw:rt",
                                    "sydney_forecast",
                                    rating.display(),
                                    traffic_light_code=rating.tlc())
                 set_statistic_data("air_pollution",
                                    "syd:rt",
                                    "sydney_forecast",
                                    rating.display(),
                                    traffic_light_code=rating.tlc())
             except HTMLParseError:
                 pass
             self.row_text = []