Пример #1
0
def doplot(plotdate):
    day = dt.make_day(plotdate) # datetime for start and end of day
    # Time from now to the 1st and last available reading
    # Used to limit the range available in the datepicker
    deltas = reading_extents_offset()
    template_args = {"start": 0 - deltas.start.days,
                     "end": deltas.end.days,
                     "day": day}
    template = 'today.html'
    if not dt.is_today(plotdate):
        template = 'default.html'
        temps = JSONTemps.dbval2json(get_readings(day))
        template_args["readings"] = json.dumps(temps)

    return template, template_args
Пример #2
0
def doplot(plotdate):
    day = dt.make_day(plotdate)  # datetime for start and end of day
    # Time from now to the 1st and last available reading
    # Used to limit the range available in the datepicker
    deltas = reading_extents_offset()
    template_args = {
        "start": 0 - deltas.start.days,
        "end": deltas.end.days,
        "day": day
    }
    template = 'today.html'
    if not dt.is_today(plotdate):
        template = 'default.html'
        temps = JSONTemps.dbval2json(get_readings(day))
        template_args["readings"] = json.dumps(temps)

    return template, template_args
Пример #3
0
    def add_val(self, time, val):
        ''' Add a value to the json file

        Arguments:
        time should be a timestamp of the reading, same form as time.time()
        val is the value of the reading to be added
        '''

        # JSON is only for today, if we are tring to add a value for another
        # day discard it
        if not dt.is_today(time):
            return
        # if We've moved into a new day empty the values
        if not self._sameday():
            self._empty()
        # Get all of todays readings so far if we currently have none
        if len(self._curjson['plotdata']) == 0:
            self._curjson = {'plotdata':self._get_today()}
        # Now we can finally add the value to the json
        self._curjson['plotdata'].append([int(time * 1000), val])
        self.__writejson()