Skip to content

Commit

Permalink
Update README.mde File
Browse files Browse the repository at this point in the history
  • Loading branch information
IliasHad committed Jul 17, 2019
1 parent 883e00c commit a9127cd
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 206 deletions.
11 changes: 9 additions & 2 deletions README.md
Expand Up @@ -4,16 +4,23 @@ Track Your Time Spent On Coding and Make Coding a Habit

## Features

Track Your Coding Time by Programming language and files
Track Your Coding Time

Offline tracking time

Earn points from your coding time

Exclude project from being tracked (Beta)

We don't share your data with any third party

Share your goals using the web app with others developers to stay accountable



## Requirements

You need API Key and you can get it from [HabitScript Setttings](https://habit-script.herokuapp.com/signup)
You need API Key and you can get it from [HabitScript Setttings](https://habit-script.herokuapp.com/signup) (If you want to visualize your data in the web app)


## Release Notes
Expand Down
8 changes: 3 additions & 5 deletions package.json
Expand Up @@ -48,11 +48,9 @@
"webpack-cli": "^3.3.5"
},
"dependencies": {
"cowsay": "^1.4.0",
"express": "^4.17.1",
"fs-extra": "^8.1.0",
"lowdb": "^1.0.0",
"mkdirp": "^0.5.1",
"moment": "^2.24.0",
"moment-duration-format": "^2.3.2",
"moment-timezone": "^0.5.26",
"node-fetch": "^2.6.0",
"os": "^0.1.1"
},
Expand Down
188 changes: 83 additions & 105 deletions src/client.js
@@ -1,113 +1,91 @@

const fetch = require('node-fetch');
const apiEndpoint = require('./config');
const vscode = require('vscode');
const fs = require('fs')
const fetch = require("node-fetch");
const apiEndpoint = require("./config");
const vscode = require("vscode");
const fs = require("fs");

import { statusBar, apiKey, fileDuration } from "./extension";
import { serverIsDown } from "./offline"
import { getJSONFile } from "./dashboard"
import {getApikey} from "./login"
import { serverIsDown } from "./offline";
import { getJSONFile } from "./dashboard";
import { getApikey } from "./login";
let lastSendingData = 0;


export function sendData() {
let file = getJSONFile();
let fileDuration = [];
let data = fs.readFileSync(file);

// @ts-ignore
fileDuration = JSON.parse(data)

let url = `${apiEndpoint}duration`;
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;


console.log(url)

let body = {
fileDuration,
apiKey
}
async function sendPost() {

// @ts-ignore
let response = await fetch(url, {
method: 'POST',
// @ts-ignore
body: JSON.stringify(body),
headers: { 'Content-Type': 'application/json' }

});
let data = await response.json()
return data;
}


sendPost()


.then(data => {
console.log(data);

})
.catch(err => {
console.log(err)
// serverIsDown();
})


let file = getJSONFile();
let fileDuration = [];
let data = fs.readFileSync(file);

// @ts-ignore
fileDuration = JSON.parse(data);

let url = `${apiEndpoint}duration`;
const timeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;

console.log(url);

let body = {
fileDuration,
apiKey
};
async function sendPost() {
// @ts-ignore
let response = await fetch(url, {
method: "POST",
// @ts-ignore
body: JSON.stringify(body),
headers: { "Content-Type": "application/json" }
});
let data = await response.json();
return data;
}

sendPost()
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
// serverIsDown();
});
}










// Check API Is Valid
// Check API Is Valid
export function checkApi() {
console.log('CHeck Api')

let url = `${apiEndpoint}duration/u/${apiKey}`
console.log(url)

let editors = {
name: "vs_code",
connected_at: new Date().toISOString()
}
let isValid;
// @ts-ignore
fetch(url, {

method: 'POST',
body: JSON.stringify(editors),
headers: { 'Content-Type': 'application/json' }
})
.then(response => {

return response.json()
})
.then(resData => {
console.log(resData)
if (resData !== undefined) {

vscode.window.showInformationMessage('Congratulations, Codabits is now active!');
}
else {
vscode.window.showInformationMessage('Oops, API Key is not valid!');

getApikey()
}
})

.catch((err) => {
getApikey()
console.log(err)
})

return isValid;
}
console.log("CHeck Api");

let url = `${apiEndpoint}duration/u/${apiKey}`;
console.log(url);

let editors = {
name: "vs_code",
connected_at: new Date().toISOString()
};
let isValid;
// @ts-ignore
fetch(url, {
method: "POST",
body: JSON.stringify(editors),
headers: { "Content-Type": "application/json" }
})
.then(response => {
return response.json();
})
.then(resData => {
console.log(resData);
if (resData !== undefined) {
vscode.window.showInformationMessage(
"Congratulations, Codabits is now active!"
);
} else {
vscode.window.showInformationMessage("Oops, API Key is not valid!");

getApikey();
}
})

.catch(err => {
getApikey();
console.log(err);
});

return isValid;
}
70 changes: 19 additions & 51 deletions src/dashboard.js
@@ -1,7 +1,8 @@
const os = require("os");
var moment = require("moment");

const { workspace, window, ViewColumn } = require("vscode");

import { humanizeMinutes } from "./data";
const fs = require("fs");

let fileDuration = [];
Expand Down Expand Up @@ -53,10 +54,11 @@ export function getJSONFile() {

function addDashboardContent() {
dashboardContent += "\n\n";
dashboardContent += `Today Coding Time: ${getTodayCodingTime(fileDuration)}`;
dashboardContent += `Today Coding Time: ${humanizeMinutes(
getTodayCodingTime(fileDuration)
)}`;
dashboardContent += "\n\n";

dashboardContent += `Most Productive Day: ${getDateFormat(
dashboardContent += `Most Productive Day: ${humanizeDate(
getMostProductiveDay(fileDuration)
)}`;
dashboardContent += "\n\n";
Expand All @@ -71,32 +73,33 @@ function addDashboardContent() {
dashboardContent += `Sort File By Duration`;
dashboardContent += "\n\n";
sortFileByDuration(fileDuration).forEach(el => {
dashboardContent += `File Name: ${el.fileName} Coding Time: ${
el.duration
}`;
dashboardContent += `File Name: ${
el.fileName
} Coding Time: ${humanizeMinutes(el.duration)}`;
});
dashboardContent += "\n\n";
console.log(sortLanguageByDuration(fileDuration));

dashboardContent += `Sort File By Language`;
dashboardContent += "\n\n";
sortLanguageByDuration(fileDuration).forEach(el => {
dashboardContent += `Language: ${el.language} Coding Time: ${el.duration}`;
dashboardContent += `Language: ${
el.language
} Coding Time: ${humanizeMinutes(el.duration)}`;
});
return dashboardContent;
}

// Format Date
function getDateFormat(date) {
const dd = new Date(date).getDate();
const mm = new Date(date).getMonth() + 1;
const yy = new Date(date).getFullYear();
return `${mm}-${dd}-${yy}`;
export function getDateFormat(date) {
return moment(date).format("MM-DD-YYYY");
}

function humanizeDate(date) {
return moment(date).format("dddd, MMMM Do YYYY");
}
function getHours(date) {
const hrs = new Date(date).getHours();
return hrs;
return moment(date).format("hh:mm a");
}

function getTodayCodingTime(duration) {
Expand Down Expand Up @@ -154,12 +157,7 @@ function sortLanguageByDuration(durations) {
}

export function openDashboardFile() {
/* fs.writeFile(file, dashboardContent, (err) => {
if (err) throw err;
console.log('The file has been saved!');
});*/
//fs.appendFileSync(file, dashboardContent, "UTF-8",{'flags': 'a+'});

// @ts-ignore
fs.writeFileSync(file, dashboardContent, "UTF-8", { flags: "as+" });

Expand All @@ -170,35 +168,5 @@ export function openDashboardFile() {
});
});
console.log(fileDuration.length);
if (fileDuration.length > 0) {
console.log(getTodayCodingTime(fileDuration));
console.log(getMostProductiveDay(fileDuration));
console.log(getMostProductivTimeOfeDay(fileDuration));
console.log(getMostUsedLanguage(fileDuration));
console.log(sortFileByDuration(fileDuration));
console.log(sortLanguageByDuration(fileDuration));
}
}

function humanizeMinutes(sec) {
// convert Secondes to Minutes
let min = sec / 60;
min = min || 0;
let str = "";
if (min === 1) {
str = "1 min";
} else if (min === 60) {
str = "1 hr";
} else if (min > 60) {
let hrs = min / 60;
if (hrs % 1 === 0) {
str = hrs.toFixed(0) + " hrs";
} else {
str = (Math.round(hrs * 10) / 10).toFixed(1) + " hrs";
}
} else {
// less than 60 seconds
str = min.toFixed(0) + " min";
}
return str;
}

0 comments on commit a9127cd

Please sign in to comment.