Changeset - 35503d1d83e7
[Not reviewed]
default
0 7 0
Dennis Fink - 9 years ago 2016-03-15 20:02:10
dennis.fink@c3l.lu
Update
7 files changed with 574 insertions and 36 deletions:
0 comments (0 inline, 0 general)
spaceapi/schema/sensors.json
Show inline comments
 
{"people_now_present": {"required": ["value"], "type": "object", "properties": {"names": {"type": "array", "items": {"type": "string"}}, "location": {"type": "string"}, "description": {"type": "string"}, "value": {"type": "number"}, "name": {"type": "string"}}}, "wind": {"required": ["properties", "location"], "type": "object", "properties": {"location": {"type": "string"}, "description": {"type": "string"}, "properties": {"required": ["speed", "gust", "direction", "elevation"], "type": "object", "properties": {"speed": {"required": ["value", "unit"], "type": "object", "properties": {"unit": {"enum": ["m/s", "km/h", "kn"]}, "value": {"type": "number"}}}, "elevation": {"required": ["value", "unit"], "type": "object", "properties": {"unit": {"enum": ["m"]}, "value": {"type": "number"}}}, "direction": {"required": ["value", "unit"], "type": "object", "properties": {"unit": {"enum": ["\u00b0"]}, "value": {"type": "number"}}}, "gust": {"required": ["value", "unit"], "type": "object", "properties": {"unit": {"enum": ["m/s", "km/h", "kn"]}, "value": {"type": "number"}}}}}, "name": {"type": "string"}}}, "total_member_count": {"required": ["value"], "type": "object", "properties": {"location": {"type": "string"}, "description": {"type": "string"}, "value": {"type": "number"}, "name": {"type": "string"}}}, "barometer": {"required": ["value", "unit", "location"], "type": "object", "properties": {"description": {"type": "string"}, "location": {"type": "string"}, "unit": {"enum": ["hPA"]}, "value": {"type": "number"}, "name": {"type": "string"}}}, "humidity": {"required": ["value", "unit", "location"], "type": "object", "properties": {"description": {"type": "string"}, "location": {"type": "string"}, "unit": {"enum": ["%"]}, "value": {"type": "number"}, "name": {"type": "string"}}}, "account_balance": {"required": ["value", "unit"], "type": "object", "properties": {"description": {"type": "string"}, "location": {"type": "string"}, "unit": {"enum": ["BTC", "EUR", "USD", "GBP"]}, "value": {"type": "number"}, "name": {"type": "string"}}}, "radiation": {"beta": {"type": "array", "items": {"required": ["value", "unit"], "type": "object", "properties": {"description": {"type": "string"}, "dead_time": {"type": "number"}, "unit": {"enum": ["cpm", "r/h", "\u00b5Sv/h", "mSv/a", "\u00b5Sv/a"]}, "conversion_factor": {"type": "number"}, "location": {"type": "string"}, "value": {"type": "number"}, "name": {"type": "string"}}}}, "gamma": {"type": "array", "items": {"required": ["value", "unit"], "type": "object", "properties": {"description": {"type": "string"}, "dead_time": {"type": "number"}, "unit": {"enum": ["cpm", "r/h", "\u00b5Sv/h", "mSv/a", "\u00b5Sv/a"]}, "conversion_factor": {"type": "number"}, "location": {"type": "string"}, "value": {"type": "number"}, "name": {"type": "string"}}}}, "type": "object", "beta_gamma": {"type": "array", "items": {"required": ["value", "unit"], "type": "object", "properties": {"description": {"type": "string"}, "dead_time": {"type": "number"}, "unit": {"enum": ["cpm", "r/h", "\u00b5Sv/h", "mSv/a", "\u00b5Sv/a"]}, "conversion_factor": {"type": "number"}, "location": {"type": "string"}, "value": {"type": "number"}, "name": {"type": "string"}}}}, "alpha": {"type": "array", "items": {"required": ["value", "unit"], "type": "object", "properties": {"description": {"type": "string"}, "dead_time": {"type": "number"}, "unit": {"enum": ["cpm", "r/h", "\u00b5Sv/h", "mSv/a", "\u00b5Sv/a"]}, "conversion_factor": {"type": "number"}, "location": {"type": "string"}, "value": {"type": "number"}, "name": {"type": "string"}}}}}, "power_consumption": {"required": ["value", "unit", "location"], "type": "object", "properties": {"description": {"type": "string"}, "location": {"type": "string"}, "unit": {"enum": ["mW", "W", "VA"]}, "value": {"type": "number"}, "name": {"type": "string"}}}, "door_locked": {"required": ["value", "location"], "type": "object", "properties": {"location": {"type": "string"}, "description": {"type": "string"}, "value": {"type": "boolean"}, "name": {"type": "string"}}}, "temperature": {"required": ["value", "unit", "location"], "type": "object", "properties": {"description": {"type": "string"}, "location": {"type": "string"}, "unit": {"enum": ["\u00b0C", "\u00b0F", "K", "\u00b0De", "\u00b0N", "\u00b0R", "\u00b0R\u00e9", "\u00b0R\u00f8"]}, "value": {"type": "number"}, "name": {"type": "string"}}}, "beverage_supply": {"required": ["value", "unit"], "type": "object", "properties": {"description": {"type": "string"}, "location": {"type": "string"}, "unit": {"enum": ["btl", "crt"]}, "value": {"type": "number"}, "name": {"type": "string"}}}, "network_connections": {"required": ["value"], "type": "object", "properties": {"description": {"type": "string"}, "type": {"enum": ["wifi", "cable", "spacenet"]}, "location": {"type": "string"}, "machines": {"type": "array", "items": {"type": "object", "properties": {"mac": {"type": "string"}, "name": {"type": "string"}}}}, "value": {"type": "number"}, "name": {"type": "string"}}}}
 
\ No newline at end of file
 
{
 
   "account_balance" : {
 
      "type" : "object",
 
      "required" : [
 
         "value",
 
         "unit"
 
      ],
 
      "properties" : {
 
         "value" : {
 
            "type" : "number"
 
         },
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "unit" : {
 
            "enum" : [
 
               "BTC",
 
               "EUR",
 
               "USD",
 
               "GBP"
 
            ]
 
         },
 
         "description" : {
 
            "type" : "string"
 
         }
 
      }
 
   },
 
   "people_now_present" : {
 
      "properties" : {
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "names" : {
 
            "type" : "array",
 
            "items" : {
 
               "type" : "string"
 
            }
 
         },
 
         "description" : {
 
            "type" : "string"
 
         },
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "value" : {
 
            "type" : "number"
 
         }
 
      },
 
      "required" : [
 
         "value"
 
      ],
 
      "type" : "object"
 
   },
 
   "temperature" : {
 
      "properties" : {
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "value" : {
 
            "type" : "number"
 
         },
 
         "description" : {
 
            "type" : "string"
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "unit" : {
 
            "enum" : [
 
               "°C",
 
               "°F",
 
               "K",
 
               "°De",
 
               "°N",
 
               "°R",
 
               "°Ré",
 
               "°Rø"
 
            ]
 
         }
 
      },
 
      "required" : [
 
         "value",
 
         "unit",
 
         "location"
 
      ],
 
      "type" : "object"
 
   },
 
   "barometer" : {
 
      "properties" : {
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "value" : {
 
            "type" : "number"
 
         },
 
         "unit" : {
 
            "enum" : [
 
               "hPA"
 
            ]
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "description" : {
 
            "type" : "string"
 
         }
 
      },
 
      "required" : [
 
         "value",
 
         "unit",
 
         "location"
 
      ],
 
      "type" : "object"
 
   },
 
   "radiation" : {
 
      "beta" : {
 
         "type" : "array",
 
         "items" : {
 
            "properties" : {
 
               "location" : {
 
                  "type" : "string"
 
               },
 
               "unit" : {
 
                  "enum" : [
 
                     "cpm",
 
                     "r/h",
 
                     "µSv/h",
 
                     "mSv/a",
 
                     "µSv/a"
 
                  ]
 
               },
 
               "description" : {
 
                  "type" : "string"
 
               },
 
               "conversion_factor" : {
 
                  "type" : "number"
 
               },
 
               "dead_time" : {
 
                  "type" : "number"
 
               },
 
               "value" : {
 
                  "type" : "number"
 
               },
 
               "name" : {
 
                  "type" : "string"
 
               }
 
            },
 
            "type" : "object",
 
            "required" : [
 
               "value",
 
               "unit"
 
            ]
 
         }
 
      },
 
      "alpha" : {
 
         "type" : "array",
 
         "items" : {
 
            "properties" : {
 
               "unit" : {
 
                  "enum" : [
 
                     "cpm",
 
                     "r/h",
 
                     "µSv/h",
 
                     "mSv/a",
 
                     "µSv/a"
 
                  ]
 
               },
 
               "location" : {
 
                  "type" : "string"
 
               },
 
               "description" : {
 
                  "type" : "string"
 
               },
 
               "dead_time" : {
 
                  "type" : "number"
 
               },
 
               "conversion_factor" : {
 
                  "type" : "number"
 
               },
 
               "name" : {
 
                  "type" : "string"
 
               },
 
               "value" : {
 
                  "type" : "number"
 
               }
 
            },
 
            "type" : "object",
 
            "required" : [
 
               "value",
 
               "unit"
 
            ]
 
         }
 
      },
 
      "gamma" : {
 
         "items" : {
 
            "type" : "object",
 
            "required" : [
 
               "value",
 
               "unit"
 
            ],
 
            "properties" : {
 
               "description" : {
 
                  "type" : "string"
 
               },
 
               "conversion_factor" : {
 
                  "type" : "number"
 
               },
 
               "dead_time" : {
 
                  "type" : "number"
 
               },
 
               "unit" : {
 
                  "enum" : [
 
                     "cpm",
 
                     "r/h",
 
                     "µSv/h",
 
                     "mSv/a",
 
                     "µSv/a"
 
                  ]
 
               },
 
               "location" : {
 
                  "type" : "string"
 
               },
 
               "value" : {
 
                  "type" : "number"
 
               },
 
               "name" : {
 
                  "type" : "string"
 
               }
 
            }
 
         },
 
         "type" : "array"
 
      },
 
      "beta_gamma" : {
 
         "items" : {
 
            "properties" : {
 
               "location" : {
 
                  "type" : "string"
 
               },
 
               "unit" : {
 
                  "enum" : [
 
                     "cpm",
 
                     "r/h",
 
                     "µSv/h",
 
                     "mSv/a",
 
                     "µSv/a"
 
                  ]
 
               },
 
               "dead_time" : {
 
                  "type" : "number"
 
               },
 
               "conversion_factor" : {
 
                  "type" : "number"
 
               },
 
               "description" : {
 
                  "type" : "string"
 
               },
 
               "value" : {
 
                  "type" : "number"
 
               },
 
               "name" : {
 
                  "type" : "string"
 
               }
 
            },
 
            "required" : [
 
               "value",
 
               "unit"
 
            ],
 
            "type" : "object"
 
         },
 
         "type" : "array"
 
      },
 
      "type" : "object"
 
   },
 
   "network_connections" : {
 
      "required" : [
 
         "value"
 
      ],
 
      "type" : "object",
 
      "properties" : {
 
         "machines" : {
 
            "items" : {
 
               "properties" : {
 
                  "name" : {
 
                     "type" : "string"
 
                  },
 
                  "mac" : {
 
                     "type" : "string"
 
                  }
 
               },
 
               "type" : "object"
 
            },
 
            "type" : "array"
 
         },
 
         "value" : {
 
            "type" : "number"
 
         },
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "type" : {
 
            "enum" : [
 
               "wifi",
 
               "cable",
 
               "spacenet"
 
            ]
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "description" : {
 
            "type" : "string"
 
         }
 
      }
 
   },
 
   "beverage_supply" : {
 
      "required" : [
 
         "value",
 
         "unit"
 
      ],
 
      "type" : "object",
 
      "properties" : {
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "value" : {
 
            "type" : "number"
 
         },
 
         "unit" : {
 
            "enum" : [
 
               "btl",
 
               "crt"
 
            ]
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "description" : {
 
            "type" : "string"
 
         }
 
      }
 
   },
 
   "door_locked" : {
 
      "properties" : {
 
         "description" : {
 
            "type" : "string"
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "value" : {
 
            "type" : "boolean"
 
         },
 
         "name" : {
 
            "type" : "string"
 
         }
 
      },
 
      "type" : "object",
 
      "required" : [
 
         "value",
 
         "location"
 
      ]
 
   },
 
   "humidity" : {
 
      "properties" : {
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "value" : {
 
            "type" : "number"
 
         },
 
         "unit" : {
 
            "enum" : [
 
               "%"
 
            ]
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "description" : {
 
            "type" : "string"
 
         }
 
      },
 
      "required" : [
 
         "value",
 
         "unit",
 
         "location"
 
      ],
 
      "type" : "object"
 
   },
 
   "wind" : {
 
      "properties" : {
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "description" : {
 
            "type" : "string"
 
         },
 
         "properties" : {
 
            "type" : "object",
 
            "required" : [
 
               "speed",
 
               "gust",
 
               "direction",
 
               "elevation"
 
            ],
 
            "properties" : {
 
               "speed" : {
 
                  "required" : [
 
                     "value",
 
                     "unit"
 
                  ],
 
                  "type" : "object",
 
                  "properties" : {
 
                     "unit" : {
 
                        "enum" : [
 
                           "m/s",
 
                           "km/h",
 
                           "kn"
 
                        ]
 
                     },
 
                     "value" : {
 
                        "type" : "number"
 
                     }
 
                  }
 
               },
 
               "direction" : {
 
                  "type" : "object",
 
                  "required" : [
 
                     "value",
 
                     "unit"
 
                  ],
 
                  "properties" : {
 
                     "unit" : {
 
                        "enum" : [
 
                           "°"
 
                        ]
 
                     },
 
                     "value" : {
 
                        "type" : "number"
 
                     }
 
                  }
 
               },
 
               "gust" : {
 
                  "required" : [
 
                     "value",
 
                     "unit"
 
                  ],
 
                  "type" : "object",
 
                  "properties" : {
 
                     "value" : {
 
                        "type" : "number"
 
                     },
 
                     "unit" : {
 
                        "enum" : [
 
                           "m/s",
 
                           "km/h",
 
                           "kn"
 
                        ]
 
                     }
 
                  }
 
               },
 
               "elevation" : {
 
                  "type" : "object",
 
                  "required" : [
 
                     "value",
 
                     "unit"
 
                  ],
 
                  "properties" : {
 
                     "unit" : {
 
                        "enum" : [
 
                           "m"
 
                        ]
 
                     },
 
                     "value" : {
 
                        "type" : "number"
 
                     }
 
                  }
 
               }
 
            }
 
         },
 
         "location" : {
 
            "type" : "string"
 
         }
 
      },
 
      "type" : "object",
 
      "required" : [
 
         "properties",
 
         "location"
 
      ]
 
   },
 
   "total_member_count" : {
 
      "properties" : {
 
         "description" : {
 
            "type" : "string"
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "value" : {
 
            "type" : "number"
 
         },
 
         "name" : {
 
            "type" : "string"
 
         }
 
      },
 
      "required" : [
 
         "value"
 
      ],
 
      "type" : "object"
 
   },
 
   "power_consumption" : {
 
      "required" : [
 
         "value",
 
         "unit",
 
         "location"
 
      ],
 
      "type" : "object",
 
      "properties" : {
 
         "name" : {
 
            "type" : "string"
 
         },
 
         "value" : {
 
            "type" : "number"
 
         },
 
         "location" : {
 
            "type" : "string"
 
         },
 
         "unit" : {
 
            "enum" : [
 
               "mW",
 
               "W",
 
               "VA"
 
            ]
 
         },
 
         "description" : {
 
            "type" : "string"
 
         }
 
      }
 
   }
 
}
spaceapi/sensors.py
Show inline comments
 
@@ -8,14 +8,13 @@ import jsonschema
 
from flask import Blueprint, jsonify, request, abort, current_app
 

	
 
from .auth import httpauth
 
#from .active import save_last_state
 
from .utils import first, fuzzy_list_find, ActiveStatus
 

	
 
sensors_views = Blueprint('sensors', __name__)
 

	
 
ALLOWED_SENSORS_KEYS = json.load(
 
    open(resource_filename('spaceapi', 'schema/sensors.json'),
 
         encoding='utf-8')
 
        encoding='utf-8')
 
)
 

	
 
RADIATON_SUBKEYS = frozenset(('alpha', 'beta', 'gamma', 'beta_gamma'))
spaceapi/templates/base.html
Show inline comments
 
@@ -8,8 +8,14 @@
 

	
 
{% block body %}
 
  <div class="container">
 
    {% block navbar %}
 
    {% endblock %}
 
    <div class="navbar navbar-default">
 
      <div class="navbar-collapse collapse">
 
        <ul class="nav navbar-nav">
 
          <li><a href="{{ url_for('root.index') }}">State</a></li>
 
          <li><a href="{{ url_for('root.open') }}">Change state</a></li>
 
        </ul>
 
      </div>
 
    </div>
 
    <div class="row" id="content">
 
      <div class="col-md-12">
 
        {% block content %}
spaceapi/templates/index.html
Show inline comments
 
@@ -2,10 +2,10 @@
 

	
 
{% block content %}
 
    {% if status['state']['open'] %}
 
      <img src="{{ url_for('static', filename='open.png') }}"></img>
 
      <p>Yes, we're open!</p>
 
      <img src="{{ url_for('static', filename='open.png') }}" class="center-block"></img>
 
      <p class="text-center">Yes, we're open!</p>
 
    {% else %}
 
      <img src="{{ url_for('static', filename='closed.png') }}"></img>
 
      <p>Sorry, we're closed!</p>
 
      <img src="{{ url_for('static', filename='closed.png') }}" class="center-block"></img>
 
      <p class="text-center">Sorry, we're closed!</p>
 
    {% endif %}
 
{% endblock %}
spaceapi/templates/open.html
Show inline comments
 
{% extends "base.html" %}
 

	
 
{% block content %}
 
  <form method="POST">
 
    <div class="form-group">
 
      <input type="submit" name="open" value="open">
 
      <input type="submit" name="close" value="close">
 
    </div>
 
  </form>
 
  <div class="text-center">
 
    <form method="POST" style="display: inline-block;">
 
      <input type="submit" name="open" value="open" class="btn btn-success btn-lg">
 
      <input type="submit" name="close" value="close" class="btn btn-danger btn-lg">
 
    </form>
 
  </div>
 
{% endblock %}
spaceapi/utils.py
Show inline comments
 
@@ -12,8 +12,6 @@ if not os.path.exists(default_json_file)
 
elif not os.path.isfile(default_json_file):
 
    raise RuntimeError('default.json is not a file!')
 

	
 
_default_json = {}
 

	
 

	
 
class Singleton:
 

	
 
@@ -32,33 +30,24 @@ class Singleton:
 
class ActiveStatus(Singleton, dict):
 

	
 
    def reload(self):
 
        global _default_json
 

	
 
        with open(default_json_file, encoding='utf-8') as f:
 
            _default_json = json.load(f)
 
            self.update(json.load(f))
 

	
 
        if os.path.exists(last_state_file) and os.path.isfile(last_state_file):
 
            with open(last_state_file, encoding='utf-8') as f:
 
                self.update(json.load(f))
 

	
 
            if os.path.getmtime(last_state_file) \
 
               < os.path.getmtime(default_json_file):
 
                backup_open = self['state']['open']
 
                backup_lastchange = self['state']['lastchange']
 
                backup_sensors = self['sensors']
 
                last_state_json = json.load(f)
 

	
 
                self.update(_default_json)
 

	
 
                self['state']['open'] = backup_open
 
                self['state']['lastchange'] = backup_lastchange
 
                self['sensors'].update(backup_sensors)
 
        else:
 
            self.update(_default_json)
 
            self['state'] = last_state_json['state']
 
            self['sensors'].update(last_state_json['sensors'])
 

	
 
    def save_last_state(self):
 

	
 
        with open(last_state_file, mode='w', encoding='utf-8') as f:
 
            json.dump(self, f, sort_keys=True)
 
            last_state = {}
 
            last_state['state'] = self['state']
 
            last_state['sensors'] = self['sensors']
 
            json.dump(last_state, f, sort_keys=True)
 

	
 

	
 
def request_wants_json():
spaceapi/views.py
Show inline comments
 
@@ -32,8 +32,10 @@ def reload():
 
def open():
 
    if request.method == 'POST':
 
        if 'close' in request.form:
 
            return set_new_state('open', False)
 
            set_new_state('open', False)
 
            return redirect(url_for('root.index'))
 
        elif 'open' in request.form:
 
            return set_new_state('open', True)
 
            set_new_state('open', True)
 
            return redirect(url_for('root.index'))
 

	
 
    return render_template('open.html')
0 comments (0 inline, 0 general)