Beispiel #1
0
    def moustache(self, base={}):
        arr = []
        for x in self.data:
            arr.append(x.json(self.columns))

        return utils.dictassign(
            {
                "count":
                len(self.data),
                "time":
                int(self.process_time * 1000) / 1000,
                "data":
                arr if self.pagesize <= 0 else
                arr[self.page * self.pagesize:(self.page + 1) * self.pagesize],
                "page":
                self.page,
                "nperpage":
                self.pagesize,
                "id":
                self.id,
                "npages":
                1 if self.pagesize <= 0 else
                (int(len(self.data) / self.pagesize) +
                 (1 if len(self.data) % self.pagesize > 0 else 0)),
                "payslist":
                alloimport.ID_TO_PAYS
            }, base)
Beispiel #2
0
 def moustache(self, base={}):
     arr = []
     index = self.page * self.pagesize
     end = (self.page + 1) * self.pagesize
     if self.pagesize < 0:
         end = len(self.data)
         index = 0
     while index < end and index < len(self.data):
         x = self.data[index]
         obj = {}
         for i in range(len(self.columns)):
             if i in [3, 6, 8, 9, 10, 11]:
                 obj[self.columns[i]] = x[i].split(';') if x[i] else []
             elif i in [20]:
                 obj[self.columns[i]] = x[i].split(',') if x[i] else []
             else:
                 obj[self.columns[i]] = x[i]
         arr.append(obj)
         index += 1
     return utils.dictassign(
         {
             "count": len(self.data),
             "time": int(self.process_time * 1000) / 1000,
             "data": arr,
             "page": self.page,
             "nperpage": self.pagesize,
             "id": self.id,
             "npages": 1
         }, base)
Beispiel #3
0
 def query_metropole(self, data):
     data = utils.dictassign({}, DEFAULT_QUERY_METROPOLE, data)
     ville = data["ville"]
     age = int(data["age"])
     datemin = data["datemin"] if ("datemin" in data
                                   and data["datemin"]) else 0
     datemax = data["datemax"] if (
         "datemax" in data and data["datemax"]) else int(time.time())
     return {
         "type":
         "simple",
         "table":
         "metropole",
         "metropole":
         ville,
         "legend":
         self.get_legend("metropole"),
         "age":
         age,
         "last_update":
         utils.str_date(self.last_update("incidence_metro")),
         "headers": ["date", "age", "incidence"],
         "data":
         list(
             map(
                 lambda x: [utils.str_date(x[0])] + list(x[1:]),
                 self.exec("""
                     select date, age, incidence from incidence_metro where metropole='%s' and age=%d and 
                     date>=%d and date<=%d  order by date asc
                 """ % (ville, age, datemin, datemax))))
     }
Beispiel #4
0
    def userlist_object(self, *args):
        x = self.db.userdata.list_json()
        l = []
        for i in x:
            l.append(i)

        xr = self.db.userdata.requests
        lr = []
        for i in xr:
            lr.append(i)
        return dictassign(
            {
                "user_list": x,
                "user_list_array": l,
                "requests": xr,
                "requests_list": lr
            }, *args)
Beispiel #5
0
    def query_dep(self, data):
        data = utils.dictassign({}, DEFAULT_QUERY_DEP, data)
        dep = int(data["dep"])
        age = int(data["age"])
        datemin = data["datemin"] if ("datemin" in data
                                      and data["datemin"]) else 0
        datemax = data["datemax"] if (
            "datemax" in data and data["datemax"]) else int(time.time())

        tmp = self.exec("""
            select date, population, positif, age from incidence_dep where dep='%s' and age=%d and 
            date>=%d and date<=%d order by date asc
        """ % (dep, age, datemin, datemax))
        out = []
        i = 0
        for row in tmp:
            incidence = 0
            if i >= 7:
                for x in range(7):
                    incidence += tmp[i - x][2]
            else:
                for x in range(i):
                    incidence += tmp[i - x][2]
                incidence += row[2] * (7 - i)
            incidence = (100000 * incidence) / row[1]
            out.append([utils.str_date(row[0])] + list(row[1:]) + [incidence])
            i += 1
        return {
            "type": "simple",
            "table": "departement",
            "legend": self.get_legend("departement"),
            "departement": str(dep) + " - " + utils.resolve_dep(dep),
            "last_update": utils.str_date(self.last_update("incidence_dep")),
            "age": age,
            "headers": ["date", "population", "positif", "age", "incidence"],
            "data": out
        }
Beispiel #6
0
 def moustache(self, base={}):
     return utils.dictassign(ResultSet.moustache(self, base), {
         "name": self.name,
         "list-id": self.listid,
         "is-list": True
     })