def GenBrief(self):
        """Brief the action as a str"""

        brief = "[{0}] {1} ".format(self.TimeStamp.strftime("%H:%M"),
                                    ActionType.actionNames[self.Type])

        if self.Type in {
                ActionType.Feed, ActionType.Notes, ActionType.WakeUp,
                ActionType.SleepTime, ActionType.ComFood, ActionType.ErrStatus
        }:
            brief += self.Detail
        elif self.Type == ActionType.Poop:
            pass
        elif self.Type == ActionType.AD:
            pass
        elif self.Type == ActionType.UnKnown:
            brief += "可以尝试 '总结' 或 '一周总结' 查看萝卜成长状态。"
        elif self.Type == ActionType.FallSleep:
            tnow = cn_utility.GetNowForUTC8()
            delta_minutes = int((tnow - self.TimeStamp).total_seconds() / 60)
            brief += "已经睡了{0}小时{1}分钟".format(int(delta_minutes / 60),
                                             delta_minutes % 60)
        else:
            pass
        return brief
Exemplo n.º 2
0
def NeedAD(rlSQL):
    ad_action = rlSQL.GetLastAD()
    n = cn_utility.GetNowForUTC8()
    hour_delta = (n - ad_action.TimeStamp).total_seconds() / 3600
    #print(ad_action.TimeStamp, n, hour_delta)
    #print (hour_delta)
    return hour_delta > 23
Exemplo n.º 3
0
def refreshDB():
    now = cn_utility.GetNowForUTC8()
    actions = enumPartition(now.strftime("%Y%m"))
    GenLocalStroyLine(now, actions)

    last_month = (now.replace(day=1)  - datetime.timedelta(days=1))
    actions = enumPartition(last_month.strftime("%Y%m"))
    GenLocalStroyLine(last_month, actions)
Exemplo n.º 4
0
def WarningForADorCa(rlSQL):
    ad_action = rlSQL.GetLastAD()
    ca_action = rlSQL.GetLastCa()
    n = cn_utility.GetNowForUTC8()

    ad_hour_delta = (n - ad_action.TimeStamp).total_seconds() / 3600
    ca_hour_delta = (n - ca_action.TimeStamp).total_seconds() / 3600

    if (ad_hour_delta <= 2) or (ca_hour_delta <= 2):
        return ""
    elif ad_hour_delta > 23:
        return "\n该考虑吃AD了。"
    elif ca_hour_delta > 23:
        return  #disable ca check for now
        return "\n该考虑吃钙片了。"

    return ""
Exemplo n.º 5
0
def dumpToLocal(table):
    month_cursor = cn_utility.GetNowForUTC8()
    skipped = 3
    with open( table + ".csv", 'w', encoding='utf-8') as csvout:
        fOut = csv.writer(csvout, delimiter='\t', quoting = csv.QUOTE_NONE, quotechar='')
        while skipped > 0:
            
            partition = month_cursor.strftime("%Y%m")
            contents = azuretable_service.query_entities('robertlog'+table, filter="PartitionKey eq '%s'"%partition, select='description')
            
            sum = 0
            for c in contents :
                fOut.writerow(c.description)
                sum+=1
            if sum == 0 :
                skipped = skipped - 1
            
            month_cursor = month_cursor.replace(day=1)  - datetime.timedelta(days=1)
Exemplo n.º 6
0
    def GenResponse(self, action):
        response = "抱歉没听懂."
        
        if action.Type == ActionType.Feed:
            response = "收到,萝卜在{1}吃了{0}".format(action.Detail, action.TimeStamp.strftime( "%H:%M"))
        elif action.Type == ActionType.Reports:
            response = "统计结果:"
            cur = datetime.datetime.utcnow() + datetime.timedelta(days=2)
            actions = self.rlSQL.GetActionReports(30)
            actions.sort(key=lambda a:a.TimeStamp)
            lastmilk = sleepstatus = Action()
            for a in actions:
                if a.Status == Action.Deleted:
                    continue

                if a.Type == ActionType.FallSleep:
                    sleepstatus = a
                    continue
                elif a.Type == ActionType.WakeUp:
                    sleepstatus = a
                elif a.Type == ActionType.Feed:
                    lastmilk = a

                if a.Type not in self.actiontype_skip_log :
                    if a.TimeStamp.day != cur.day:
                        cur = a.TimeStamp
                        response += "\n{0}日(第{1}天)记录:\n".format(cur.strftime("%m-%d"), \
                        config.get_days_to_birth(cur))
                    if len(response) > 250:
                        response = response[-250:]
                    response += (a.GenBrief() + "\n")

            tnow = cn_utility.GetNowForUTC8()
            if sleepstatus.Type == ActionType.FallSleep:
                #is sleeping
                response += (sleepstatus.GenBrief() + "\n")
            elif sleepstatus.Type == ActionType.WakeUp:
                delta_minutes = int((tnow - sleepstatus.TimeStamp).total_seconds()/60)
                if delta_minutes > 240:
                    response += "\n醒了{0}小时{1}分钟了,该睡了".format(int(delta_minutes/60), delta_minutes%60) 
            else:
                #don't find last status skip
                pass
            
            #disable milk alert for now
            #delta_minutes = int((tnow - lastmilk.TimeStamp).total_seconds()/60)
            #if delta_minutes > 240:
                #response += "\n上次喂奶是{0}小时{1}分钟前:{2}".format(int(delta_minutes/60), delta_minutes%60, lastmilk.GenBrief())

        elif action.Type == ActionType.WeeklyReports:
            response = "统计结果: \n"
            cur = datetime.datetime.utcnow() + datetime.timedelta(days=2)
            actions = self.rlSQL.GetActionReports(300)
            milk = 0
            breast = 0
            breastNum = 0
            poop = 0
            sleep = 0
            daysShown = 0
            pillstaken = 0
            comFoodCount = 0
            snackCount = 0
            notesPerDay = ""
            for a in actions:
                if a.Status == Action.Deleted:
                    continue

                if a.TimeStamp.day != cur.day and (milk !=0 or breast !=0):                        
                    #response += "{0}日:奶瓶{1}mL,母乳{2}次共{3}分钟,睡觉{5}小时{6}分钟,大便{4}次\n".format(\
                    #cur.strftime("%m-%d"), milk, breastNum, breast, poop, int(sleep/60), sleep%60)
                    #no breast milk version
                    response += "{0}日:奶瓶{1}mL,辅食{5}次,零食{6}次,睡觉{3}小时{4}分钟,大便{2}次\n".format(\
                    cur.strftime("%m-%d"), milk, poop, int(sleep/60), sleep%60, comFoodCount, snackCount)
                    
                    if len(notesPerDay) > 0:
                        response += "今日备注: {0}\n".format(notesPerDay)
                    
                    if pillstaken > 0:
                        response += "吃药{0}次\n".format(pillstaken)
                    
                    milk = 0
                    breast = 0 
                    poop = 0
                    breastNum = 0
                    sleep = 0
                    pillstaken = 0
                    comFoodCount = 0
                    snackCount  = 0
                    notesPerDay = ""
                    daysShown += 1
                    if daysShown >= 8 : break
                cur = a.TimeStamp
                if a.Type == ActionType.Feed:
                    nums = re.findall(r"\d+",a.Detail)
                    if len(nums) > 0:
                        d = int(nums[0])
                        if a.Detail.find("母乳") >= 0:
                            breast += d
                            breastNum += 1
                        elif a.Detail.find("奶瓶") >= 0:
                            milk += d
                elif a.Type == ActionType.Poop:
                    poop += 1
                elif a.Type == ActionType.WakeUp:
                    ect = extract_cn_time()
                    sleep += ect.extract_time_delta(a.Detail)
                    #print(cur, sleep, a.Detail)
                elif a.Type == ActionType.ComFood:
                    comFoodCount += 1
                elif a.Type == ActionType.Snacks:
                    snackCount += 1
                elif a.Type == ActionType.Pills:
                    pillstaken += 1
                elif a.Type == ActionType.Notes:
                    #notesPerDay += "{0}日{1}\t".format(cur.strftime("%m-%d"),a.GenBrief())
                    notesPerDay += a.GenBrief()
                    pass

            if (milk !=0 or breast !=0) and daysShown < 7:                 
                #response += "{0}日:奶瓶{1}mL,母乳{2}次共{3}分钟,睡觉{5}小时{6}分钟,大便{4}次\n".format(\
                #    cur.strftime("%m-%d"), milk, breastNum, breast, poop, int(sleep/60), sleep%60)
                #no breast version
                response += "{0}日:奶瓶{1}mL,辅食{5}次,零食{6}次,睡觉{3}小时{4}分钟,大便{2}次\n".format(\
                    cur.strftime("%m-%d"), milk, poop, int(sleep/60), sleep%60, comFoodCount, snackCount)
                
                if len(notesPerDay) > 0:
                        response += "今日备注: {0}\n".format(notesPerDay)
                    
                if pillstaken > 0:
                        response += "吃药{0}次\n".format(pillstaken)
    
        elif action.Type == ActionType.Remove:
            response = "请输入要删除的项目序号\n"
            actions = self.rlSQL.GetActionReports(6)
            actions.sort(key=lambda a:a.TimeStamp)
            for a in actions:
                if a.Status == Action.Deleted:
                    continue
                response += "序号:{0} 内容:{1},{2}\n".format(\
                    a.ActionID, self.user_mapping.get(a.FromUser, a.FromUser), a.GenBrief())
        elif action.Type == ActionType.RemoveSpecific:
            self.rlSQL.DeleteAction(int(action.message.RawContent))
            response ="已删除一条记录.\n"
        elif action.Type == ActionType.ListImage:
            return action.ImageList
        elif action.Type == ActionType.DebugMsg:
            msg_list = self.rlSQL.GetLastNumMsg(30)
            response = "List:\n"
            for m in msg_list:
                response +="[{0}] {1}:{2} \n".format(m.TimeStamp.strftime( "%H:%M"), self.user_mapping.get(m.FromUser, m.FromUser), m.RawContent)
        elif action.Type == ActionType.NoPermission:
            response = "抱歉您没有权限,可以尝试 '总结' 或 '一周总结' 查看萝卜成长状态。"
        elif action.Type == ActionType.ComFoodList:
            response = "吃饭记录:\n"
            foodList = self.rlSQL.GetActionList( ActionType.ComFood, 80)
            foodList.sort(key=lambda a:a.TimeStamp)
            cur = datetime.datetime.utcnow() + datetime.timedelta(days=2)
            for f in foodList:
                if f.TimeStamp.day != cur.day: #a new day 
                    response += "\n[{0}] {1} ".format(f.TimeStamp.strftime("%m-%d"), f.Detail)
                    cur = f.TimeStamp
                else:
                    response += f.Detail #f.GenBrief()
        elif action.Type == ActionType.ViewNotes:
            response = "备注记录:\n"
            noteList = self.rlSQL.GetActionList( ActionType.Notes, 5)
            noteList.sort(key=lambda a:a.TimeStamp)
            cur = datetime.datetime.utcnow() + datetime.timedelta(days=2)
            for f in noteList:
                if f.TimeStamp.day != cur.day: #a new day 
                    response += "\n[{0}] {1} ".format(f.TimeStamp.strftime("%m-%d"), f.Detail)
                    cur = f.TimeStamp
                else:
                    response += f.Detail #f.GenBrief()
        else:
            response = action.GenBrief()

        response += warning.GetWarnings(self.rlSQL)
        return response