コード例 #1
0
def update_stat():
    global last_update_stat
    now = time.time()

    if now < util.strtostamp(util.next_month(last_update_stat)):
        return False
    end = util.strtostamp(util.first_day(now))
    print end
    time_from = util.strtostamp(last_update_stat)
    time_to = util.strtostamp(util.next_month(time_from))
    while time_to <= end:
        #update diet_stat
        diet_stat = diet_statistics(time_from, time_to)
        stat = diet_stat[1]
        for row in stat.values():
            row['stamp_from'] = util.stamptostr(time_from)
            row['stamp_to'] = util.stamptostr(time_to)
            myredis.insert('diet_stat', row)
        #update cook_stat
        cook_stat = cook_statistics(time_from, time_to)
        stat = cook_stat[1]
        for row in stat.values():
            row['stamp_from'] = util.stamptostr(time_from)
            row['stamp_to'] = util.stamptostr(time_to)
            myredis.insert('cook_stat', row)

        time_from = time_to
        time_to = util.strtostamp(util.next_month(time_from))
コード例 #2
0
 def post(self):
     time_from = json_decode(self.get_argument('from'))
     time_to = json_decode(self.get_argument('to'))
     time_from = util.strtostamp(time_from)
     time_to = util.strtostamp(time_to)
     detail = data.get_detail(time_from, time_to)
     response = {'status': 'ok', 'detail': detail}
     self.write(json_encode(response))
コード例 #3
0
 def post(self):
     time_from = json_decode(self.get_argument('from'))
     time_to = json_decode(self.get_argument('to'))
     time_from = util.strtostamp(time_from)
     time_to = util.strtostamp(time_to)
     order_history = datalayer.get_order(time_from, time_to)
     feedback = datalayer.get_feedback(time_from, time_to)
     response = {
         'status': 'ok',
         'order': order_history,
         'feedback': feedback
     }
     self.write(json_encode(response))
コード例 #4
0
def get_cookinfo(time_from, time_to):
    r = re.compile(r'^([0-9]{4})\.([0-9]{2}|[0-9])\.([0-9]{2}|[0-9])$')
    if not r.match(time_from) or not r.match(time_to):
        return None
    time_from = util.strtostamp(time_from)
    time_to = util.strtostamp(time_to)
    sql = 'select fid, did, sum(num) from cook_history where stamp >= %s and stamp < %s group by fid, did' % (
        time_from, time_to)
    conn = MySQLdb.connect(host=mysql.HOST,
                           port=mysql.PORT,
                           user=mysql.USER,
                           passwd=mysql.PASSWD,
                           db=mysql.DB,
                           charset='utf8')
    conn.autocommit(False)
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()
    res = filter(lambda x: x['role'] == 'cook', faculty)
    res = map(
        lambda x: {
            'fid': x['fid'],
            'name': x['name'],
            'num': 0,
            'num_per': 0,
            'total': 0,
            'total_per': 0
        }, res)
    num_total = 0
    total_total = 0
    for row in cursor.fetchall():
        fid = row[0]
        did = row[1]
        num = row[2]
        d = filter(lambda x: x['did'] == did, diet)
        item = filter(lambda x: x['fid'] == fid, res)
        if len(d) != 1 or len(item) != 1:
            continue
        d = d[0]
        item = item[0]
        item['num'] += num

        item['total'] += num * d['price']
        num_total += num
        total_total += num * d['price']
    for row in res:
        row['num_per'] = '%.2d' % (row['num'] * 100 / num_total)
        row['total_per'] = '%.2d' % (row['total'] * 100 / total_total)
    res.sort(key=lambda x: x['fid'])
    return res, num_total, total_total
コード例 #5
0
def get_onecookinfo(fid, time_from, time_to):
    r = re.compile(r'^([0-9]{4})\.([0-9]{2}|[0-9])\.([0-9]{2}|[0-9])$')
    if not r.match(time_from) or not r.match(time_to):
        return None
    time_from = util.strtostamp(time_from)
    time_to = util.strtostamp(time_to)
    sql = 'select * from cook_history where fid = %s and stamp >= %s and stamp < %s' % (
        fid, time_from, time_to)
    sql = 'select feedback.did, fb, sum(feedback.num) from (' + sql + ') as p, feedback where p.uid = feedback.uid group by feedback.did, fb '
    conn = MySQLdb.connect(host=mysql.HOST,
                           port=mysql.PORT,
                           user=mysql.USER,
                           passwd=mysql.PASSWD,
                           db=mysql.DB,
                           charset='utf8')
    conn.autocommit(False)
    cursor = conn.cursor()
    cursor.execute(sql)
    conn.commit()

    res = map(
        lambda x: {
            'did': x['did'],
            'name': x['name'],
            'num': 0,
            'good': 0,
            'normal': 0,
            'bad': 0
        }, diet)
    for row in cursor.fetchall():
        did = row[0]
        fb = row[1]
        num = row[2]
        t = filter(lambda x: x['did'] == did, res)
        if len(t) != 1:
            continue
        item = t[0]
        item['num'] += num

        if fb == -1:
            item['bad'] = num
        elif fb == 0:
            item['normal'] = num
        elif fb == 1:
            item['good'] = num
    res.sort(key=lambda x: x['did'])
    return res
コード例 #6
0
def get_cookinfo(time_from, time_to):
    r = re.compile(r'^([0-9]{4})\.([0-9]{2}|[0-9])\.([0-9]{2}|[0-9])$')
    if not r.match(time_from) or not r.match(time_to):
        return None
    time_from = util.strtostamp(time_from)
    time_to = util.strtostamp(time_to)
    sql = 'select fid, did, sum(num) from cook_history where stamp >= %s and stamp < %s group by fid, did' % (
        time_from, time_to)
    cursor = mysql.query(sql)
    res = filter(lambda x: x['role'] == 'cook', data.faculty)
    res = map(
        lambda x: {
            'fid': x['fid'],
            'name': x['name'],
            'num': 0,
            'num_per': 0,
            'total': 0,
            'total_per': 0
        }, res)
    num_total = 0
    total_total = 0
    for row in cursor.fetchall():
        fid = row[0]
        did = row[1]
        num = row[2]
        d = filter(lambda x: x['did'] == did, data.diet)
        item = filter(lambda x: x['fid'] == fid, res)
        if len(d) != 1 or len(item) != 1:
            continue
        d = d[0]
        item = item[0]
        item['num'] += num

        item['total'] += num * d['price']
        num_total += num
        total_total += num * d['price']
    for row in res:
        row['num_per'] = '%.2d' % (row['num'] * 100 / num_total)
        row['total_per'] = '%.2d' % (row['total'] * 100 / total_total)
    res.sort(key=lambda x: x['fid'])
    return res, num_total, total_total
コード例 #7
0
def get_onecookinfo(fid, time_from, time_to):
    r = re.compile(r'^([0-9]{4})\.([0-9]{2}|[0-9])\.([0-9]{2}|[0-9])$')
    if not r.match(time_from) or not r.match(time_to):
        return None
    time_from = util.strtostamp(time_from)
    time_to = util.strtostamp(time_to)
    sql = 'select * from cook_history where fid = %s and stamp >= %s and stamp < %s' % (
        fid, time_from, time_to)
    sql = 'select feedback.did, fb, sum(feedback.num) from (' + sql + ') as p, feedback where p.did = feedback.did group by feedback.did, fb '
    cursor = mysql.query(sql)

    res = map(
        lambda x: {
            'did': x['did'],
            'name': x['name'],
            'num': 0,
            'good': 0,
            'normal': 0,
            'bad': 0
        }, data.diet)
    for row in cursor.fetchall():
        did = row[0]
        fb = row[1]
        num = row[2]
        t = filter(lambda x: x['did'] == did, res)
        if len(t) != 1:
            continue
        item = t[0]
        item['num'] += num

        if fb == -1:
            item['bad'] = num
        elif fb == 0:
            item['normal'] = num
        elif fb == 1:
            item['good'] = num
    res.sort(key=lambda x: x['did'])
    return res
コード例 #8
0
ファイル: data.py プロジェクト: Jackie-Linzz/autodiet2
    'name': 'cook',
    'role': 'cook',
    'password': '******'
}, {
    'fid': '0005',
    'name': '5',
    'role': 'cook',
    'password': '******'
}]

order_history = [{
    'uid': '1',
    'did': 1,
    'puid': '1',
    'num': 1,
    'stamp': util.strtostamp('2015.1.8')
}, {
    'uid': '2',
    'did': 2,
    'puid': '1',
    'num': 1,
    'stamp': util.strtostamp('2015.1.8')
}, {
    'uid': '3',
    'did': 3,
    'puid': '3',
    'num': 0.5,
    'stamp': util.strtostamp('2015.2.8')
}, {
    'uid': '4',
    'did': 4,
コード例 #9
0
              {'cid': 3, 'name': '主食', 'ord': 3, 'description': ''})


diet = [{'did': 1, 'name': '宫保鸡丁', 'price': 26.0, 'cid': 3, 'ord': 3, 'picture': '', 'base': 1, 'description': '', },
        {'did': 2, 'name': '状元养生炖', 'price': 26.0, 'cid': 3, 'ord': 3, 'picture': '', 'base': 1, 'description': '', },
        {'did': 3, 'name': '花生米', 'price': 26.0, 'cid': 1, 'ord': 1, 'picture': '', 'base': 0.5, 'description': '', },
        {'did': 4, 'name': '海带', 'price': 26.0, 'cid': 1, 'ord': 1, 'picture': '', 'base': 1, 'description': '', }]


faculty = [{'fid': '0001', 'name': 'jackie', 'role': 'founder', 'password': '******'},
           {'fid': '0002', 'name': 'manager', 'role': 'manager', 'password': '******'},
           {'fid': '0003', 'name': 'waiter', 'role': 'waiter', 'password': '******'},
           {'fid': '0004', 'name': 'cook', 'role': 'cook', 'password': '******'},
           {'fid': '0005', 'name': '5', 'role': 'cook', 'password': '******'}]

order_history = [{'uid': '1', 'did': 1, 'puid': '1', 'num': 1, 'stamp': util.strtostamp('2015.1.8')},
                 {'uid': '2', 'did': 2, 'puid': '1', 'num': 1, 'stamp': util.strtostamp('2015.1.8')},
                 {'uid': '3', 'did': 3, 'puid': '3', 'num': 0.5, 'stamp': util.strtostamp('2015.2.8')},
                 {'uid': '4', 'did': 4, 'puid': '4', 'num': 1, 'stamp': util.strtostamp('2015.3.8')}]

customer_history = [{'session': 'a', 'desk': '1', 'desk_uid': '1', 'stamp': util.strtostamp('2015.1.8')},
                    {'session': 'b', 'desk': '2', 'desk_uid': '3', 'stamp': util.strtostamp('2015.2.8')},
                    {'session': 'c', 'desk': '1', 'desk_uid': '4', 'stamp': util.strtostamp('2015.3.8')}]

cook_history = [{'fid': '0004', 'uid': '1', 'did': 1, 'num': 1, 'stamp': util.strtostamp('2015.1.8')},
                {'fid': '0004', 'uid': '2', 'did': 2, 'num': 1, 'stamp': util.strtostamp('2015.1.8')},
                {'fid': '0005', 'uid': '3', 'did': 3, 'num': 1, 'stamp': util.strtostamp('2015.2.8')},
                {'fid': '0005', 'uid': '4', 'did': 4, 'num': 1, 'stamp': util.strtostamp('2015.3.8')}]

feedback = [{'uid': '2', 'did': 2, 'num': 1, 'fb': -1, 'stamp': util.strtostamp('2015.1.8')},
            {'uid': '2', 'did': 2, 'num': 1, 'fb': 1, 'stamp': util.strtostamp('2015.1.8')},