]> ToastFreeware Gitweb - chrisu/seepark.git/blobdiff - web/seepark_web.py
Remove deprecated/removed json_encoder.
[chrisu/seepark.git] / web / seepark_web.py
index d7f25c522a281f4d110440bf812fa2d7c551ea2e..13fb6e4586299cf03d010fbd3e6f3004b452a35a 100644 (file)
@@ -42,21 +42,6 @@ DAY_OF_WEEK_DE = [
     'Sonntag']
 
 
-# https://stackoverflow.com/a/37350445
-def sqlalchemy_model_to_dict(model):
-    return {c.key: getattr(model, c.key)
-        for c in inspect(model).mapper.column_attrs}
-
-
-class JSONEncoder(flask.json.JSONEncoder):
-    def default(self, object):
-        if isinstance(object, datetime.datetime):
-            return object.isoformat()
-        elif isinstance(object, db.Model):
-            return sqlalchemy_model_to_dict(object)
-        return super().default(object)
-
-
 def parse_datetime(date_str):
     return datetime.datetime.strptime(date_str, '%Y-%m-%dT%H:%M:%S')
 
@@ -81,7 +66,6 @@ cityid = config.get('openweathermap', 'cityid')
 mainsensor = config.get('webapp', 'mainsensor')
 
 app = Flask(__name__)
-app.json_encoder = JSONEncoder
 app.config['SQLALCHEMY_DATABASE_URI'] = get_sqlalchemy_database_uri(config)
 app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
 db = SQLAlchemy(app)
@@ -394,12 +378,15 @@ def report(year, month):
                 x, y = data
                 for d in days_datetime:
                     report_datetime = datetime.datetime.combine(d.date(), t)
-                    closest_index = np.argmin(np.abs(x - report_datetime))
-                    if abs(x[closest_index] - report_datetime) > datetime.timedelta(hours=1):
+                    if len(x) == 0:
                         cell = 'N/A'
                     else:
-                        value = y[closest_index]
-                        cell = '{:.1f}'.format(value)
+                        closest_index = np.argmin(np.abs(x - report_datetime))
+                        if abs(x[closest_index] - report_datetime) > datetime.timedelta(hours=1):
+                            cell = 'N/A'
+                        else:
+                            value = y[closest_index]
+                            cell = '{:.1f}'.format(value)
                     row_cells.append(cell)
                 cells.append(row_cells)
         row_colors = list(ntimes(report_colors + ['w'], len(report_times)))