Добавил новые таблицы
This commit is contained in:
53
db/db.py
53
db/db.py
@@ -2,16 +2,18 @@ import logging
|
||||
import sqlite3 as sq
|
||||
|
||||
from classes import Activity, Tag
|
||||
from enums import ActivityType
|
||||
|
||||
|
||||
class Database:
|
||||
def __init__(self, db_name: str):
|
||||
try:
|
||||
self.con = sq.connect(db_name)
|
||||
self.con.cursor().executescript('''CREATE TABLE IF NOT EXISTS "activities" (
|
||||
self.con.cursor().executescript('''
|
||||
CREATE TABLE IF NOT EXISTS "activities" (
|
||||
"id" VARCHAR NOT NULL UNIQUE,
|
||||
"description" VARCHAR NOT NULL,
|
||||
"time_spent" NUMERIC NOT NULL,
|
||||
"time_spent" NUMERIC(3, 3) NOT NULL,
|
||||
"date_start" DATETIME NOT NULL,
|
||||
"date_end" DATETIME,
|
||||
"is_tracked" BOOLEAN NOT NULL DEFAULT false,
|
||||
@@ -36,18 +38,25 @@ CREATE TABLE IF NOT EXISTS "vetro_projects" (
|
||||
PRIMARY KEY("id")
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "time_entry" (
|
||||
CREATE TABLE IF NOT EXISTS "activity_types" (
|
||||
"id" INTEGER NOT NULL UNIQUE,
|
||||
"activity_id" VARCHAR NOT NULL,
|
||||
"task_id" INTEGER NOT NULL,
|
||||
"title" VARCHAR NOT NULL,
|
||||
PRIMARY KEY("id")
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS "time_entry" (
|
||||
"id" INTEGER PRIMARY KEY,
|
||||
"date" DATETIME NOT NULL,
|
||||
"time_spent" NUMERIC NOT NULL,
|
||||
"description" VARCHAR NOT NULL,
|
||||
"activity_type" INTEGER NOT NULL CHECK(activity_type in (9, 8, 57, 58, 60)),
|
||||
PRIMARY KEY("id"),
|
||||
"activity_id" VARCHAR NOT NULL,
|
||||
"time_spent" NUMERIC(3, 3) NOT NULL,
|
||||
"task_id" INTEGER NOT NULL,
|
||||
"activity_type_id" INTEGER NOT NULL,
|
||||
FOREIGN KEY ("activity_id") REFERENCES "activities"("id")
|
||||
ON UPDATE NO ACTION ON DELETE NO ACTION,
|
||||
FOREIGN KEY ("task_id") REFERENCES "activities"("task_id")
|
||||
ON UPDATE NO ACTION ON DELETE NO ACTION,
|
||||
FOREIGN KEY ("activity_type_id") REFERENCES "activity_types"("id")
|
||||
ON UPDATE NO ACTION ON DELETE NO ACTION
|
||||
);
|
||||
''')
|
||||
@@ -82,19 +91,16 @@ CREATE TABLE IF NOT EXISTS "time_entry" (
|
||||
for act in activities:
|
||||
try:
|
||||
cur.execute(
|
||||
"INSERT INTO time_entry VALUES(?, ?, ? ,? ,? ,? ,? ,? ,? ,? ,? ,?)",
|
||||
"""INSERT INTO time_entry
|
||||
(date, description, activity_id, time_spent, task_id, activity_type_id)
|
||||
VALUES(?,?,?,?,?,?)""",
|
||||
(
|
||||
act.id,act.vetro_project_id,
|
||||
act.vetro_project_title,
|
||||
act.task_id,
|
||||
act.date_start.date(),
|
||||
act.description,
|
||||
act.task_title,
|
||||
act.tag_id,
|
||||
act.project_id,
|
||||
act.id,
|
||||
act.time_spent,
|
||||
act.date_start,
|
||||
act.date_end,
|
||||
act.is_tracked
|
||||
act.task_id,
|
||||
ActivityType.DEVELOPMENT
|
||||
)
|
||||
)
|
||||
self.con.commit()
|
||||
@@ -127,6 +133,11 @@ CREATE TABLE IF NOT EXISTS "time_entry" (
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
||||
|
||||
|
||||
|
||||
def insert_activity_types(self, activity_types: dict):
|
||||
cur = self.con.cursor()
|
||||
for k,v in activity_types.items():
|
||||
try:
|
||||
cur.execute("INSERT INTO activity_types VALUES(?, ?)", (k, v))
|
||||
self.con.commit()
|
||||
except Exception as e:
|
||||
logging.error(e)
|
||||
|
||||
14
track.py
14
track.py
@@ -30,6 +30,8 @@ def main():
|
||||
user_id=USER_ID
|
||||
)
|
||||
red = RedmineAPI(config.REDMINE_TOKEN)
|
||||
db.insert_tags(clock.get_tags())
|
||||
db.insert_vetro_projects(config.VETRO_PROJECTS)
|
||||
activities = clock.get_activities(
|
||||
**{
|
||||
"start": format_date(start),
|
||||
@@ -38,12 +40,16 @@ def main():
|
||||
},
|
||||
)
|
||||
db.insert_activities(activities)
|
||||
db.insert_tags(clock.get_tags())
|
||||
db.insert_vetro_projects(config.VETRO_PROJECTS)
|
||||
db.insert_time_entries(activities)
|
||||
db.insert_activity_types({
|
||||
9: "Разработка",
|
||||
8: "Бизнес-анализ",
|
||||
57: "Code review",
|
||||
58: "Внутренние консультации",
|
||||
60: "Поддержка",
|
||||
})
|
||||
# tracked_activities = red.track_activities(activities)
|
||||
# clock.mark_tracked(tracked_activities)
|
||||
for activity in activities:
|
||||
print(activity)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user