def plotDayStartEndSleepTimes(daySleepData, day):

    mondayData = daySleepData[AnalyseData.daySwitcher(day)]

    # This gets that start sleep datetime in a list.
    mondayStartDate = mondayData['sleepStartTimestampGMT'].to_list()

    # This gets the start sleep date.
    mondayStartDay = [date.date() for date in mondayStartDate]

    # This gets the start sleep time.
    mondayStartTime = [date.time() for date in mondayStartDate]

    # This does the same except for the end sleep time.
    mondayEndDate = mondayData['sleepEndTimestampGMT'].to_list()
    mondayEndDay = [date.date() for date in mondayEndDate]

    mondayEndTime = [date.time() for date in mondayEndDate]

    plt.scatter(mondayStartDay, mondayStartTime, color='blue')
    plt.scatter(mondayEndDay, mondayEndTime, color='red')
    plt.gcf().autofmt_xdate()
    plt.title('Start and end times for %s' % str(day))
    # plt.gcf().autofmt_ydate()
    plt.show()

    return None
예제 #2
0
 def getDataAndAnalyse(self,bot,qlist):
     username = bot.friends()[0].raw.get('NickName')
     dir = os.path.join('userdata', username)
     if os.path.exists(dir):
         qlist.put(['获取好友信息','检测到好友信息文件已经存在\n\n'+'*' * 30 + '\n'])
         qlist.join()
     else:
         DataStorage.getFriendData(bot,qlist)
         qlist.put(['获取好友信息','正在检测图片信息,请耐心等待\n\n'+'*' * 30 + '\n'])
         qlist.join()
         Imgdetect.getHeadImgContentByThread(username,20)
         qlist.put(['获取好友信息', '图片检测完毕\n\n' + '*' * 30 + '\n'])
         qlist.join()
     qlist.put(['获取好友信息','开始生成图表\n\n'+'*' * 30 + '\n'])
     qlist.join()
     AnalyseData.analyseAll(username)
     qlist.put(['获取好友信息', '图表生成完毕\n\n' + '*' * 30 + '\n'+'路径为:'+os.path.join('userdata',username,'result.html')+'\n\n'+'*' * 30 + '\n'])
     qlist.join()
     os.system('"E:/Firefox/firefox.exe" '+os.path.join('userdata',username,'result.html'))
import numpy as np
import sys, os
import matplotlib.pyplot as plt
import datetime
from datetime import timedelta
import matplotlib.pyplot as plt
import glob
import seaborn as sns

import ExtractGarminData
import AnalyseData

from scipy.stats import norm
import pylab

import warnings
warnings.filterwarnings("ignore")


# Plots a line for each sleep type for each day of the week.
def plotDayTrend(sleepData):

    return None


if __name__ == "__main__":

    sleepData = AnalyseData.loadConfirmedData()

    plotDayTrend(sleepData)
        'deepSleepSeconds', 'lightSleepSeconds', 'remSleepSeconds',
        'awakeSleepSeconds'
    ]
    sizes = [
        sleepMeanValues[0], sleepMeanValues[1], sleepMeanValues[2],
        sleepMeanValues[3]
    ]
    colours = ['darkblue', 'blue', 'purple', 'pink']
    # explode = (0.1, 0, 0, 0)  # explode 1st slice

    patches, texts = plt.pie(sizes, colors=colours, shadow=True, startangle=90)
    plt.legend(patches, labels, loc="best")
    plt.axis('equal')
    plt.tight_layout()
    fileName = '../AnalysisFigures/MeanSleepSecondsPerType'

    plt.savefig(fileName + '.eps', format='eps', dpi=2200, bbox_inches='tight')
    plt.savefig(fileName + '.pdf', format='pdf', dpi=2200, bbox_inches='tight')
    plt.close('all')

    return None


if __name__ == "__main__":

    sleepData = AnalyseData.loadConfirmedData()

    sleepMeanValues = AnalyseData.getMeanValues()

    plotMeanPieChart(sleepMeanValues)
예제 #5
0
    sns.distplot(saturdaySleepList, color="dodgerblue", ax=axes[5], axlabel='Saturday Sleep Hours')
    sns.distplot(sundaySleepList, color="dodgerblue", ax=axes[6], axlabel='Sunday Sleep Hours')
    fig.show()
    plt.show()


    kwargs = dict(hist_kws={'alpha':.6}, kde_kws={'linewidth':2})
    plt.figure(figsize=(10,3), dpi=100)
    sns.distplot(mondaySleepList, label='Monday Sleep Hours', **kwargs)
    sns.distplot(tuesdaySleepList, label='Tuesday Sleep Hours', **kwargs)
    sns.distplot(wednesdaySleepList, label='Wednesday Sleep Hours', **kwargs)
    sns.distplot(thursdaySleepList, label='Thursday Sleep Hours', **kwargs)
    sns.distplot(fridaySleepList, label='Friday Sleep Hours', **kwargs)
    sns.distplot(saturdaySleepList, label='Saturday Sleep Hours', **kwargs)
    sns.distplot(sundaySleepList, label='Sunday Sleep Hours', **kwargs)
    plt.legend()
    plt.show()


    return None


if __name__ == "__main__":

    sleepData = AnalyseData.loadConfirmedData()

    # This returns a vector where each item holds a dataframe for each day of the weeks data separated.
    daySleepData = AnalyseData.dayOfWeekData(sleepData)

    plotDaySleepDistribution(daySleepData)
예제 #6
0
    date_str = sys.argv[1][12:]

print 'Analysis target date = ',date_str

#下载当前日期的配置文件
config_file_name = download_path[mode] + date_str + conf_file_suff
config_file_url = fixed_conf_url + date_str + conf_file_suff
check_file_name = download_path[mode] + date_str + check_file_suff
#先判断有无标记文件,避免重复下载
if os.path.isfile(check_file_name):
    print 'No contest today.'
    exit()
FF.download_url_to_file(config_file_url, config_file_name)
#检测配置文件是否正确,如果不正确=没有比赛,直接退出
#如果是非法的配置文件,不需要转码,本身就是utf-8
if AD.legal_config_file(config_file_name) == no_contest:
    debug_info_file = open(debug_file_name[mode], 'w')
    debug_info_file.writelines('No contest')
    debug_info_file.close()
    chk_file = open(check_file_name, 'w')
    chk_file.write('No contest')
    chk_file.close()
    print 'No contest'
    exit()
FF.file_convert_pagecode(config_file_name, source_pagecode, config_file_name, dest_pagecode)

AD.load_config_file(config_file_name)

#下载主投票所的首页文件
FF.download_url_to_file(home_page_url, home_page_file_name[mode])
FF.file_convert_pagecode(home_page_file_name[mode], source_pagecode, home_page_file_name[mode], dest_pagecode)
예제 #7
0
    return None


def monthlyViolinPlots(sleepData):

    # The dataframe needs to be formatted such that one column shows the total sleep for that whole day.
    sleepData['AccumulatedSleep'] = sleepData['deepSleepSeconds'] + sleepData[
        'lightSleepSeconds'] + sleepData['remSleepSeconds']
    sleepData['AccumulatedSleep'] = sleepData['AccumulatedSleep'].div(60**2)
    sleepData['Month'] = sleepData['calendarDate'].apply(
        lambda t: t.strftime('%Y-%m'))
    sns.violinplot(data=sleepData, x='Month', y='AccumulatedSleep')
    plt.show()

    print(sleepData)

    return None


if __name__ == "__main__":

    sleepData = AnalyseData.loadConfirmedData()

    # This returns a vector where each item holds a dataframe for each day of the weeks data separated.
    # daySleepData = dayOfWeekData(sleepData)

    # timeViolinPlots(daySleepData)

    sleepData = AnalyseData.removeNanEntries(sleepData)
    monthlyViolinPlots(sleepData)