def get_firstday_lastday(year=None, month=None):
"""
:param year: intstr
:param month: intstr
:return: firstDay: datetime.date
lastDay: datetime.date
"""
if year:
year = int(year)
else:
year = datetime.date.today().year
if month:
month = int(month)
else:
month = datetime.date.today().month
-sharp
firstDayWeekDay, monthRange = calendar.monthrange(year, month)
-sharp
firstDay = datetime.date(year=year, month=month, day=1)
lastDay = datetime.date(year=year, month=month, day=monthRange)
return firstDay, lastDay
-sharp !/usr/bin/python3
-sharp encoding=utf-8
import user_list
import function
import datetime
reg_u = user_list.get_registereduser()
month_list, month1, month2, month3, month4, month5, month6, \
month7, month8, month9, month10, month11, month12 = \
[], [], [], [], [], [], [], [], [], [], [], [], []
for i in range(1, 13):
date = function.get_firstday_lastday(2018, i)
for d in date:
day = datetime.datetime.strptime(str(d), "%Y-%m-%d")
month_list.append(day)
for u in reg_u:
if month_list[0] <= u["regDate"] < month_list[2]:
month1.append(u)
elif month_list[2] <= u["regDate"] < month_list[4]:
month2.append(u)
elif month_list[4] <= u["regDate"] < month_list[6]:
month3.append(u)
elif month_list[6] <= u["regDate"] < month_list[8]:
month4.append(u)
elif month_list[8] <= u["regDate"] < month_list[10]:
month5.append(u)
elif month_list[10] <= u["regDate"] < month_list[12]:
month6.append(u)
elif month_list[12] <= u["regDate"] < month_list[14]:
month7.append(u)
elif month_list[14] <= u["regDate"] < month_list[16]:
month8.append(u)
elif month_list[16] <= u["regDate"] < month_list[18]:
month9.append(u)
elif month_list[18] <= u["regDate"] < month_list[20]:
month10.append(u)
elif month_list[20] <= u["regDate"] < month_list[22]:
month11.append(u)
elif month_list[22] <= u["regDate"] < month_list[23]:
month12.append(u)
print(
len(month1), len(month2), len(month3), len(month4), len(month5), len(month6),
len(month7), len(month8), len(month9), len(month10), len(month11), len(month12)
)
early self-study, the above is to do a monthly statistics of the whole year (please give me some advice on optimizing the code)
also want to do some all days in a month
and all hours in a day
you can make a statistical tree or line chart later. I don"t know how to start
Don"t be humble and ask for advice. Thank you very much.