diff options
author | dusoleil <howcansocksbereal@gmail.com> | 2022-08-26 20:43:03 -0400 |
---|---|---|
committer | dusoleil <howcansocksbereal@gmail.com> | 2022-08-26 20:43:03 -0400 |
commit | 6963eb6cb0f7d15c97f44b9ca439be321edb8a8f (patch) | |
tree | 190990c2497d7f0ad8b2cfed87bab53bff496fbf | |
parent | 5756a8f8ed23f0af88b9a351fbbde7417ac82c2f (diff) | |
download | Planner-6963eb6cb0f7d15c97f44b9ca439be321edb8a8f.tar.gz Planner-6963eb6cb0f7d15c97f44b9ca439be321edb8a8f.zip |
accidentally wasn't tracking any of the data model objects
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | data_model/DataHelpers.gd | 24 | ||||
-rw-r--r-- | data_model/SubTask.gd | 24 | ||||
-rw-r--r-- | data_model/Task.gd | 49 | ||||
-rw-r--r-- | data_model/TimeSlot.gd | 30 | ||||
-rw-r--r-- | data_model/data.db | bin | 0 -> 36864 bytes | |||
-rw-r--r-- | data_model/dbms.gd | 16 |
7 files changed, 144 insertions, 0 deletions
@@ -5,6 +5,7 @@ export_presets.cfg *.translation .mono/ data_*/ +!data_model/ .vscode/ *.exe *.dll diff --git a/data_model/DataHelpers.gd b/data_model/DataHelpers.gd new file mode 100644 index 0000000..9e8d7cd --- /dev/null +++ b/data_model/DataHelpers.gd @@ -0,0 +1,24 @@ +class_name DataHelpers
+
+static func dummy_data(data):
+ return data
+
+static func timeofday(time):
+ var hour = time / 60
+ var minute = time % 60
+ var am = hour < 12
+ hour = hour % 12
+ if hour == 0:
+ hour = 12
+ var string = "%2d:%02d %s"
+ return string % [hour, minute, "AM" if am else "PM"]
+
+enum Frequency {DAILY, EVERY_OTHER_DAY, WEEKLY, BI_WEEKLY, MONTHLY, SIZE}
+static func frequency(freq):
+ match freq:
+ Frequency.DAILY: return "Daily"
+ Frequency.EVERY_OTHER_DAY: return "Every\nOther Day"
+ Frequency.WEEKLY: return "Weekly"
+ Frequency.BI_WEEKLY: return "Bi-Weekly"
+ Frequency.MONTHLY: return "Monthly"
+ _: return ""
diff --git a/data_model/SubTask.gd b/data_model/SubTask.gd new file mode 100644 index 0000000..fa044a5 --- /dev/null +++ b/data_model/SubTask.gd @@ -0,0 +1,24 @@ +class_name SubTask
+
+class SubTask_data:
+ var id
+ var task_id
+ var name
+ var date_completed
+
+ func _init(record):
+ self.id = record['id']
+ self.task_id = record['task_id']
+ self.name = record['name']
+ self.date_completed = record['date_completed']
+
+static func get_by_task(task_id):
+ var records = DBMS.query("""
+ SELECT * FROM "SubTasks"
+ WHERE task_id = ?
+ """,
+ [task_id])
+ var subtasks = []
+ for record in records:
+ subtasks.push_back(SubTask_data.new(record))
+ return subtasks
diff --git a/data_model/Task.gd b/data_model/Task.gd new file mode 100644 index 0000000..3da0840 --- /dev/null +++ b/data_model/Task.gd @@ -0,0 +1,49 @@ +class_name Task
+
+class Task_data:
+ var id
+ var name
+ var description
+ var frequency
+ var estimated_length
+ var date_completed
+
+ func _init(record):
+ self.id = record['id']
+ self.name = record['name']
+ self.description = record['description']
+ self.frequency = record['frequency']
+ self.estimated_length = record['estimated_length']
+ self.date_completed = record['date_completed']
+
+static func get_by_id(id):
+ var record = DBMS.query("""
+ SELECT * FROM "Tasks"
+ WHERE id = ?
+ """,
+ [id])
+ record = record[0]
+ return Task_data.new(record)
+
+static func get_by_timeslot(timeslot_id):
+ var records = DBMS.query("""
+ SELECT "Tasks".* FROM "Tasks"
+ INNER JOIN "TimeSlotTasks" ON "Tasks".id = "TimeSlotTasks".task_id
+ WHERE "TimeSlotTasks".timeslot_id = ?
+ """,
+ [timeslot_id])
+ var tasks = []
+ for record in records:
+ tasks.push_back(Task_data.new(record))
+ return tasks
+
+static func get_by_frequency(frequency):
+ var records = DBMS.query("""
+ SELECT * FROM "Tasks"
+ WHERE frequency = ?
+ """,
+ [frequency])
+ var tasks = []
+ for record in records:
+ tasks.push_back(Task_data.new(record))
+ return tasks
diff --git a/data_model/TimeSlot.gd b/data_model/TimeSlot.gd new file mode 100644 index 0000000..f98cd62 --- /dev/null +++ b/data_model/TimeSlot.gd @@ -0,0 +1,30 @@ +class_name TimeSlot
+
+class TimeSlot_data:
+ var id
+ var schedule_id
+ var start_time
+ var end_time
+ var name
+ var date_completed
+
+ func _init(record):
+ self.id = record['id']
+ self.schedule_id = record['schedule_id']
+ self.start_time = record['start_time']
+ self.end_time = record['end_time']
+ self.name = record['name']
+ self.date_completed = record['date_completed']
+
+static func get_by_schedule_name(schedule_name):
+ var records = DBMS.query("""
+ SELECT "TimeSlots".* FROM "TimeSlots"
+ JOIN "Schedules" ON "TimeSlots".schedule_id = "Schedules".id
+ WHERE "Schedules".name = ?
+ ORDER BY "TimeSlots".start_time
+ """,
+ [schedule_name])
+ var timeslots = []
+ for record in records:
+ timeslots.push_back(TimeSlot_data.new(record))
+ return timeslots
diff --git a/data_model/data.db b/data_model/data.db Binary files differnew file mode 100644 index 0000000..4951f46 --- /dev/null +++ b/data_model/data.db diff --git a/data_model/dbms.gd b/data_model/dbms.gd new file mode 100644 index 0000000..43c514d --- /dev/null +++ b/data_model/dbms.gd @@ -0,0 +1,16 @@ +#class_name DBMS +extends Node + +const sqlite = preload("res://addons/godot-sqlite/bin/gdsqlite.gdns") +var db_name = "res://data_model/data.db" +var db + +func _init(): + db = sqlite.new() + db.path = db_name + #db.verbosity_level = 3 + db.open_db() + +func query(sql, args): + db.query_with_bindings(sql,args) + return db.query_result |