Skip to content

Submit CodingTracker #198

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 52 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
7338e67
Create README.md
Call911plz Mar 25, 2025
a07ea5a
Added dotnet project
Call911plz Mar 25, 2025
96d7819
Merge branch 'main' of github.com:Call911plz/CodingTracker
Call911plz Mar 25, 2025
8eea066
docs: Adjust README
Call911plz Mar 25, 2025
f38a47d
refactor: add MVC files
Call911plz Mar 26, 2025
d914003
feat: add StartUI to UserInterface
Call911plz Mar 26, 2025
c8d15b0
chore: renamed Model to SessionModel
Call911plz Mar 26, 2025
918d29c
feat: add class to files
Call911plz Mar 26, 2025
b129948
feat: add StartUi
Call911plz Mar 26, 2025
9f26755
refactor: SessionModel to SessionData
Call911plz Mar 26, 2025
4a35108
feat: add SessionDBModel
Call911plz Mar 26, 2025
6e3876c
feat: add methods to SessionDBModel
Call911plz Mar 26, 2025
788faea
refactor: move MakeDB to CreateDB
Call911plz Mar 26, 2025
a146cfa
refactor: connection to class variable
Call911plz Mar 26, 2025
714902e
feat: format SelectLog
Call911plz Mar 26, 2025
5bf412a
feat: add SessionData parameter to CreateLog
Call911plz Mar 26, 2025
d6ad13a
refactor: CreateLog to InsertLog
Call911plz Mar 26, 2025
66c7c00
feat: add UpdateLog
Call911plz Mar 26, 2025
3a34a08
feat: add DeleteLog
Call911plz Mar 26, 2025
afc3158
refactor: SelectLog return dataset
Call911plz Mar 26, 2025
b3a1fac
feat: add DisplaySessionData to UserInterface
Call911plz Mar 26, 2025
72c38fe
refactor: rename InputController to MainController
Call911plz Mar 27, 2025
d1a5164
feat: add Main to MainController
Call911plz Mar 27, 2025
79d991a
refactor: rename StartUI to GetStartUIInput
Call911plz Mar 27, 2025
fa79b9d
feat: add method for getting SessionData
Call911plz Mar 27, 2025
92174b2
fix: rename UserInterface.Main to Start
Call911plz Mar 27, 2025
c0d1553
refactor: adjust DisplaySessionData
Call911plz Mar 27, 2025
273b7e8
feat: add figlet title to StartUI
Call911plz Mar 27, 2025
0f71f7d
feat: add GetTime
Call911plz Mar 27, 2025
bf8e210
feat: GetSessionData return SessionData object
Call911plz Mar 27, 2025
a3b5d30
refactor: adjust GetDate to GetDateTime
Call911plz Mar 27, 2025
88bdc1f
style: move GetSessionData vars for readability
Call911plz Mar 27, 2025
0e6d246
refactor: duration to string,add CalculateDuration
Call911plz Mar 27, 2025
0f236d9
refactor: CalculateDuration to private
Call911plz Mar 27, 2025
1aecd72
feat: connect UI, SessionDBModel, MainController
Call911plz Mar 27, 2025
e135397
refactor: make continue text not appear on exit
Call911plz Mar 27, 2025
09928a2
feat: add GetId
Call911plz Mar 28, 2025
791a320
feat: add GetIdFromDB
Call911plz Mar 28, 2025
00ff235
feat: connect Update
Call911plz Mar 28, 2025
8aa82a2
fix: GetId did not return user's id
Call911plz Mar 28, 2025
db60d4f
feat: connect Delete
Call911plz Mar 28, 2025
06e7b0e
style/doc: add comments, checked off README
Call911plz Mar 28, 2025
fead532
refactor: removed FIND enum and references
Call911plz Mar 28, 2025
0f10d0a
refactor: switch code blocks moved to methods
Call911plz Mar 28, 2025
68014d6
feat: add sort to MainController.List
Call911plz Mar 28, 2025
ed8c890
feat: add Record to record new session
Call911plz Mar 28, 2025
02e99ce
feat: Record works
Call911plz Mar 28, 2025
d7b0405
refactor: move FindAll prompts to UserInterface
Call911plz Mar 28, 2025
e8ff353
refactor: move files to folders
Call911plz Mar 28, 2025
8fc4e6f
feat: add App.config
Call911plz Mar 28, 2025
8b101f0
style: update README
Call911plz Mar 28, 2025
fd8a5ec
style: removed method test comment
Call911plz Mar 28, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<connectionStrings>
<add name="DBConnection"
connectionString="Data Source=Database\\CodingTracker.db"
providerName="Microsoft.Data.SQLite"/>
</connectionStrings>
<appSettings>
<add key="DBPath" value="Database"/>
</appSettings>
</configuration>
18 changes: 18 additions & 0 deletions CodingTracker.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Dapper" Version="2.1.66" />
<PackageReference Include="Microsoft.Data.Sqlite" Version="9.0.3" />
<PackageReference Include="Spectre.Console" Version="0.49.1" />
<PackageReference Include="Spectre.Console.Cli" Version="0.49.1" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="9.0.3" />
</ItemGroup>

</Project>
98 changes: 98 additions & 0 deletions Controller/MainController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@


using Spectre.Console;

class MainController
{
public static void Start()
{
bool shouldRun = true;
SessionDBModel.CreateDB(); // REQUIRED TO MAKE DB

while (shouldRun)
{
var startInput = UserInterface.GetStartUIInput(); // Get start menu input
var dataSet = SessionDBModel.GetAllLog("Id"); // Contains all current logs
var avaliableIds = SessionDBModel.GetIdFromDB(); // Contains all current ids
switch (startInput)
{
case Enums.MenuOption.RECORD:
Record();
break;

case Enums.MenuOption.CREATE:
Create();
break;

case Enums.MenuOption.FINDALL:
FindAll();
break;

case Enums.MenuOption.UPDATE:
Update(dataSet, avaliableIds);
break;

case Enums.MenuOption.DELETE:
Delete(dataSet, avaliableIds);
break;

case Enums.MenuOption.EXIT:
shouldRun = false;
break;
}
if (shouldRun)
{
AnsiConsole.MarkupLine("Press [bold green]Enter[/] to return to continue");
Console.Read();
}

SessionDBModel.ExitDB(); // REQUIRED TO CLOSE DB
}
}

private static void Record()
{
var data = UserInterface.GetRecordSession();
SessionDBModel.InsertLog(data);
}

static void Create()
{
var data = UserInterface.GetSessionData(); // Get log from user
SessionDBModel.InsertLog(data); // Insert Log
}

static void FindAll()
{
string userInput = "Id";
bool desc = false;
do
{
Console.Clear();
var dataSet = SessionDBModel.GetAllLog(userInput, desc);
UserInterface.DisplaySessionData(dataSet); // Show all logs

// Change sort order
userInput = UserInterface.GetSearchOrder();

if (userInput != "Exit")
desc = UserInterface.GetDescending();

}while(userInput != "Exit");
}

static void Update(List<SessionData> dataSet, int[] allIds)
{
UserInterface.DisplaySessionData(dataSet); // Show all logs
var id = UserInterface.GetId(allIds); // Get Id from user
var data = UserInterface.GetSessionData(); // Get new log from user
SessionDBModel.UpdateLog(id, data); // Update log
}

static void Delete(List<SessionData> dataSet, int[] allIds)
{
UserInterface.DisplaySessionData(dataSet); // Show all logs
var idDelete = UserInterface.GetId(allIds); // Get Id from user
SessionDBModel.DeleteLog(idDelete);
}
}
Binary file added Database\\CodingTracker.db
Binary file not shown.
6 changes: 6 additions & 0 deletions Enums.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Enums
{
public enum MenuOption {
RECORD, CREATE, FINDALL, UPDATE, DELETE, EXIT
}
}
79 changes: 79 additions & 0 deletions Model/SessionDBModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Dapper;
using Microsoft.Data.Sqlite;
using System.Configuration;


class SessionDBModel
{
static SqliteConnection connection = null;
public static void CreateDB()
{
var connectionString = ConfigurationManager.ConnectionStrings["DBConnection"].ConnectionString;
// Connect to the database
connection = new SqliteConnection(connectionString);

var sql =
$@"CREATE TABLE IF NOT EXISTS coding_sessions (
Id INTEGER PRIMARY KEY AUTOINCREMENT,
StartTime TEXT,
EndTime TEXT,
Duration TEXT)";

connection.Execute(sql);

}

public static void InsertLog(SessionData data)
{
var sql =
$@"INSERT INTO coding_sessions (StartTime, EndTime, Duration)
VALUES ('{data.StartTime}', '{data.EndTime}', '{data.Duration}')";
connection.Execute(sql);
}

public static List<SessionData> GetAllLog(string orderBy, bool desc = false)
{
var sql =
$@"SELECT *
FROM coding_sessions
ORDER BY {orderBy}";

if (desc)
sql += " DESC";
return connection.Query<SessionData>(sql).ToList();
}

public static void UpdateLog(int id, SessionData newData)
{
var sql =
$@"UPDATE coding_sessions
SET StartTime = '{newData.StartTime}',
EndTime = '{newData.EndTime}',
Duration = '{newData.Duration}'
WHERE Id = {id}";

connection.Execute(sql);
}

public static void DeleteLog(int id)
{
var sql =
$@"DELETE FROM coding_sessions
WHERE Id = {id}";

connection.Execute(sql);
}

public static void ExitDB()
{
connection.Close();
}

public static int[] GetIdFromDB()
{
var sql =
$@"SELECT * FROM coding_sessions";

return connection.Query<int>(sql).ToArray();
}
}
17 changes: 17 additions & 0 deletions Model/SessionData.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

class SessionData
{
public int Id { get; set; }
public string StartTime { get; set; }
public string EndTime { get; set; }
public string Duration { get; set; }

public DateTime StartDateTime()
{
return DateTime.Parse(StartTime);
}
public DateTime EndDateTime()
{
return DateTime.Parse(EndTime);
}
}
11 changes: 11 additions & 0 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace CodingTracker;
using Spectre.Console;

class Program
{
static void Main(string[] args)
{
// Run main
MainController.Start();
}
}
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Coding Tracker
- [x] This application has the same requirements as the previous project, except that now you'll be logging your daily coding time.
- [x] To show the data on the console, you should use the "Spectre.Console" library.
- [x] You're required to have separate classes in different files (ex. UserInput.cs, Validation.cs, CodingController.cs)
- [x] You should tell the user the specific format you want the date and time to be logged and not allow any other format.
- [x] You'll need to create a configuration file that you'll contain your database path and connection strings.
- [x] You'll need to create a "CodingSession" class in a separate file. It will contain the properties of your coding session: Id, StartTime, EndTime, Duration
- [x] The user shouldn't input the duration of the session. It should be calculated based on the Start and End times, in a separate "CalculateDuration" method.
- [x] The user should be able to input the start and end times manually.
- [x] You need to use Dapper ORM for the data access instead of ADO.NET. (This requirement was included in Feb/2024)
- [x] When reading from the database, you can't use an anonymous object, you have to read your table into a List of Coding Sessions.
- [x] Follow the DRY Principle, and avoid code repetition.

- [x] Add the possibility of tracking the coding time via a stopwatch so the user can track the session as it happens.
- [x] Let the users filter their coding records per period (weeks, days, years) and/or order ascending or descending.
- [ ] Create reports where the users can see their total and average coding session per period.
- [ ] Create the ability to set coding goals and show how far the users are from reaching their goal, along with how many hours a day they would have to code to reach their goal. You can do it via SQL queries or with C#.
Loading