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