diff --git a/lazy-timer-be/app.py b/lazy-timer-be/app.py index 35151ae..41da69a 100644 --- a/lazy-timer-be/app.py +++ b/lazy-timer-be/app.py @@ -2,7 +2,7 @@ import os import sys import json -from datetime import datetime # 处理时间 +from datetime import datetime, timedelta # 处理时间 from flask import Flask, request from flask_cors import CORS, cross_origin from flask_sqlalchemy import SQLAlchemy @@ -21,6 +21,7 @@ db = SQLAlchemy(app) # 数据库模型 class App(db.Model): + __tablename__ = 'app' id = db.Column(db.Integer, primary_key=True) # App id process = db.Column(db.Text) # appName text = db.Column(db.Text) # app窗口名称 @@ -28,17 +29,20 @@ class App(db.Model): class Period(db.Model): + __tablename__ = 'period' timeStart = db.Column(db.DateTime, primary_key=True) # 开始时间 timeEnd = db.Column(db.DateTime) # 结束时间 winId = db.Column(db.Integer) # 活动id class Tag(db.Model): + __tablename__ = 'tag' id = db.Column(db.Integer, primary_key=True) # 标签id text = db.Column(db.Text) # 标签文本 class Win(db.Model): + __tablename__ = 'win' id = db.Column(db.Integer, primary_key=True) # 活动id appId = db.Column(db.Integer) # App id text = db.Column(db.Text, nullable=True) # 活动窗口名称 @@ -52,15 +56,17 @@ class Win(db.Model): def getDayScreenUseTime(): datetimeStr1 = json.loads(request.data) datetimeStr = datetimeStr1['datetimeStr'] - struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime + struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime activityTimeList = Period.query.all() - selectedTimeList = [] # 选中的对应今天日期的时间 + selectedTimeList = [] # 选中的对应今天日期的时间 for time in activityTimeList: if time.timeStart.date() == struct_time and time.timeEnd.date() == struct_time: selectedTimeList.append(time) if (len(selectedTimeList) == 0): - sendJson = {'getDayScreenUseTimeH': 0, 'getDayScreenUseTimeM': 0, 'getDayScreenUseTimeS': 0, 'firstScreenTime': '', 'lastScreenTime': '', 'getScreenTimeSpanH': 0, 'getScreenTimeSpanM':0, 'getScreenTimeSpanS': 0 } + sendJson = {'getDayScreenUseTimeH': 0, 'getDayScreenUseTimeM': 0, 'getDayScreenUseTimeS': 0, + 'firstScreenTime': '', 'lastScreenTime': '', 'getScreenTimeSpanH': 0, 'getScreenTimeSpanM': 0, + 'getScreenTimeSpanS': 0} else: timeAmount = 0 for time in selectedTimeList: @@ -69,20 +75,59 @@ def getDayScreenUseTime(): timeAmount = timeAmount + time_diff.total_seconds() timeAmount = int(timeAmount) - getDayScreenUseTimeM, getDayScreenUseTimeS = divmod(timeAmount, 60) # 每日屏幕使用时长, 分时秒 + getDayScreenUseTimeM, getDayScreenUseTimeS = divmod(timeAmount, 60) # 每日屏幕使用时长, 分时秒 getDayScreenUseTimeH, getDayScreenUseTimeM = divmod(getDayScreenUseTimeM, 60) - firstScreenTime = selectedTimeList[0].timeStart.strftime('%H时%M分%S秒') # 第一次屏幕使用时刻, - lastScreenTime = selectedTimeList[-1].timeEnd.strftime('%H时%M分%S秒') # 最后一次屏幕使用时刻 - screenTimeSpan = int((selectedTimeList[-1].timeEnd - selectedTimeList[0].timeStart).total_seconds()) # 持续时间 + firstScreenTime = selectedTimeList[0].timeStart.strftime('%H时%M分%S秒') # 第一次屏幕使用时刻, + lastScreenTime = selectedTimeList[-1].timeEnd.strftime('%H时%M分%S秒') # 最后一次屏幕使用时刻 + screenTimeSpan = int((selectedTimeList[-1].timeEnd - selectedTimeList[0].timeStart).total_seconds()) # 持续时间 getScreenTimeSpanM, getScreenTimeSpanS = divmod(screenTimeSpan, 60) # 每日屏幕使用时长, 分时秒 getScreenTimeSpanH, getScreenTimeSpanM = divmod(getScreenTimeSpanM, 60) - sendJson = {'getDayScreenUseTimeH': getDayScreenUseTimeH, 'getDayScreenUseTimeM': getDayScreenUseTimeM, 'getDayScreenUseTimeS': getDayScreenUseTimeS, 'firstScreenTime': firstScreenTime, 'lastScreenTime': lastScreenTime, 'getScreenTimeSpanH': getScreenTimeSpanH, 'getScreenTimeSpanM': getScreenTimeSpanM, 'getScreenTimeSpanS': getScreenTimeSpanS } + sendJson = {'getDayScreenUseTimeH': getDayScreenUseTimeH, 'getDayScreenUseTimeM': getDayScreenUseTimeM, + 'getDayScreenUseTimeS': getDayScreenUseTimeS, 'firstScreenTime': firstScreenTime, + 'lastScreenTime': lastScreenTime, 'getScreenTimeSpanH': getScreenTimeSpanH, + 'getScreenTimeSpanM': getScreenTimeSpanM, 'getScreenTimeSpanS': getScreenTimeSpanS} return json.dumps(sendJson, indent=4) -@app.route('/getDayScreenUseTime', methods=['POST']) + +@app.route('/getDayScreenUse', methods=['POST']) @cross_origin() -def getDayScreenUseTime(): +def getDayScreenUse(): datetimeStr1 = json.loads(request.data) datetimeStr = datetimeStr1['datetimeStr'] - struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # 获取请求日期, struct_time数据类型为dateTime - return "1" \ No newline at end of file + struct_time = datetime.strptime(datetimeStr, "%Y-%m-%d").date() # dateTime数据类型 + struct_time_tomorrow = struct_time + timedelta(days=1) + # 连接多张表 + joinTables = Period.query.filter(Period.timeStart > struct_time).filter( + Period.timeStart < struct_time_tomorrow).filter(Period.timeEnd > struct_time).filter( + Period.timeEnd < struct_time_tomorrow).all() + + resultTables = [] + for i in joinTables: + sampleDict = {} + sampleDict['timeStart'] = i.timeStart.strftime('%H:%M:%S') + sampleDict['timeEnd'] = i.timeEnd.strftime('%H:%M:%S') + sampleDict['totolSeconds'] = (i.timeEnd - i.timeStart).seconds + queryWin = Win.query.filter(Win.id == i.winId).first() + sampleDict['activity'] = queryWin.text + sampleDict['appId'] = queryWin.appId + queryApp = App.query.filter(queryWin.appId == App.id).first() + sampleDict['appName'] = queryApp.text + queryTag = Tag.query.filter(queryApp.tagId == Tag.id).first() + sampleDict['tag'] = queryTag.text + resultTables.append(sampleDict) + + returnJson = json.dumps(resultTables) + return returnJson + + +@app.route('/getAppId', methods=['POST']) +@cross_origin() +def getAppId(): + queryAppId = App.query.all() + resultTables = [] + for i in queryAppId: + sampleDict = {} + sampleDict['id'] = i.id + sampleDict['text'] = i.text + resultTables.append(sampleDict) + return json.dumps(resultTables) diff --git a/lazy-timer-fe/package-lock.json b/lazy-timer-fe/package-lock.json index c7a547b..e48e0e1 100644 --- a/lazy-timer-fe/package-lock.json +++ b/lazy-timer-fe/package-lock.json @@ -19,6 +19,7 @@ "@syncfusion/ej2-react-richtexteditor": "^19.4.50", "@syncfusion/ej2-react-schedule": "^19.4.50", "axios": "^0.27.2", + "echarts": "^5.3.3", "echarts-for-react": "^3.0.2", "moment": "^2.29.4", "react": "^17.0.2", @@ -6497,7 +6498,6 @@ "version": "5.3.3", "resolved": "https://registry.npmmirror.com/echarts/-/echarts-5.3.3.tgz", "integrity": "sha512-BRw2serInRwO5SIwRviZ6Xgm5Lb7irgz+sLiFMmy/HOaf4SQ+7oYqxKzRHAKp4xHQ05AuHw1xvoQWJjDQq/FGw==", - "peer": true, "dependencies": { "tslib": "2.3.0", "zrender": "5.3.2" @@ -6519,8 +6519,7 @@ "node_modules/echarts/node_modules/tslib": { "version": "2.3.0", "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.3.0.tgz", - "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", - "peer": true + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" }, "node_modules/ee-first": { "version": "1.1.1", @@ -16038,7 +16037,6 @@ "version": "5.3.2", "resolved": "https://registry.npmmirror.com/zrender/-/zrender-5.3.2.tgz", "integrity": "sha512-8IiYdfwHj2rx0UeIGZGGU4WEVSDEdeVCaIg/fomejg1Xu6OifAL1GVzIPHg2D+MyUkbNgPWji90t0a8IDk+39w==", - "peer": true, "dependencies": { "tslib": "2.3.0" } @@ -16046,8 +16044,7 @@ "node_modules/zrender/node_modules/tslib": { "version": "2.3.0", "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.3.0.tgz", - "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", - "peer": true + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" } }, "dependencies": { @@ -21038,7 +21035,6 @@ "version": "5.3.3", "resolved": "https://registry.npmmirror.com/echarts/-/echarts-5.3.3.tgz", "integrity": "sha512-BRw2serInRwO5SIwRviZ6Xgm5Lb7irgz+sLiFMmy/HOaf4SQ+7oYqxKzRHAKp4xHQ05AuHw1xvoQWJjDQq/FGw==", - "peer": true, "requires": { "tslib": "2.3.0", "zrender": "5.3.2" @@ -21047,8 +21043,7 @@ "tslib": { "version": "2.3.0", "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.3.0.tgz", - "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", - "peer": true + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" } } }, @@ -28330,7 +28325,6 @@ "version": "5.3.2", "resolved": "https://registry.npmmirror.com/zrender/-/zrender-5.3.2.tgz", "integrity": "sha512-8IiYdfwHj2rx0UeIGZGGU4WEVSDEdeVCaIg/fomejg1Xu6OifAL1GVzIPHg2D+MyUkbNgPWji90t0a8IDk+39w==", - "peer": true, "requires": { "tslib": "2.3.0" }, @@ -28338,8 +28332,7 @@ "tslib": { "version": "2.3.0", "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.3.0.tgz", - "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", - "peer": true + "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==" } } } diff --git a/lazy-timer-fe/package.json b/lazy-timer-fe/package.json index 56454cf..8210d07 100644 --- a/lazy-timer-fe/package.json +++ b/lazy-timer-fe/package.json @@ -14,6 +14,7 @@ "@syncfusion/ej2-react-richtexteditor": "^19.4.50", "@syncfusion/ej2-react-schedule": "^19.4.50", "axios": "^0.27.2", + "echarts": "^5.3.3", "echarts-for-react": "^3.0.2", "moment": "^2.29.4", "react": "^17.0.2", diff --git a/lazy-timer-fe/public/index.html b/lazy-timer-fe/public/index.html index 50ad218..df9fde6 100644 --- a/lazy-timer-fe/public/index.html +++ b/lazy-timer-fe/public/index.html @@ -27,6 +27,7 @@ Learn how to configure a non-root public URL by running `npm run build`. -->
User Profile
+用户信息
} color="rgb(153, 171, 180)" @@ -28,9 +28,9 @@ const UserProfile = () => { alt="user-profile" />Michael Roberts
-Administrator
-info@shop.com
+在隐身
+管理员
+1836891291@qq.com
{props.AppName}
日期
-2022年9月5日
+2022年9月7日
Revenue Updates
+屏幕使用记录甘特图
+ {/*
$93,438 @@ -155,17 +160,19 @@ const Ecommerce = () => {
Budget
-$48,487
Expense
-Recent Transactions
@@ -263,9 +270,9 @@ const Ecommerce = () => {Weekly Stats
@@ -386,7 +393,7 @@ const Ecommerce = () => {