Skip to content

Commit c820dcd

Browse files
committed
Fill overall stats for all days
- remove unnecessary icons
1 parent 94239cd commit c820dcd

File tree

10 files changed

+200
-18
lines changed

10 files changed

+200
-18
lines changed

src/assets/css/main.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
:root {
22
--main-color: #6ebf5d;
3-
--popup-header: #f3f3f3;
3+
--popup-header: #efefef;
44
--progress-bar: #428bff;
55
}
66
::-webkit-scrollbar-track {
@@ -134,7 +134,7 @@ body {
134134
border-radius: 1px;
135135
}
136136
.tabs .content {
137-
margin-top: 30px;
137+
margin-top: 10px;
138138
}
139139
.tabs .content section {
140140
display: none;

src/assets/icons/eye.png

-764 Bytes
Binary file not shown.

src/assets/icons/heat-map-16.png

-477 Bytes
Binary file not shown.

src/assets/icons/pie-chart.png

-617 Bytes
Binary file not shown.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
<template>
2+
<div class="stats-block">
3+
<div class="row">
4+
<div class="block">
5+
<div class="header">The first active day</div>
6+
<p>{{ data.firstDay.toLocaleDateString() }}</p>
7+
</div>
8+
<div class="block">
9+
<div class="header">Number of active days</div>
10+
<p>{{ data.activeDaysTotal }}</p>
11+
</div>
12+
<div class="block">
13+
<div class="header">Total number of days</div>
14+
<p>{{ data.daysTotal }}</p>
15+
</div>
16+
</div>
17+
<div class="row">
18+
<div class="block">
19+
<div class="header">Time for today</div>
20+
<p>{{ convertSummaryTimeToString(data.todaySummaryTime) }}</p>
21+
</div>
22+
<div class="block">
23+
<div class="header">All the time</div>
24+
<p>{{ convertSummaryTimeToString(data.summaryTime) }}</p>
25+
</div>
26+
<div class="block">
27+
<div class="header">Average time on active days</div>
28+
<p>{{ convertSummaryTimeToString(data.averageTimeByActiveDays) }}</p>
29+
</div>
30+
</div>
31+
<div class="row">
32+
<div class="block">
33+
<div class="header">The most active day</div>
34+
<p>{{ data.mostActiveDay.date.toLocaleDateString() }}</p>
35+
<p>{{ convertSummaryTimeToString(data.mostActiveDay.summaryTime) }}</p>
36+
</div>
37+
<div class="block">
38+
<div class="header">The most inactive day</div>
39+
<p>{{ data.mostInactiveDay.date.toLocaleDateString() }}</p>
40+
<p>{{ convertSummaryTimeToString(data.mostInactiveDay.summaryTime) }}</p>
41+
</div>
42+
</div>
43+
</div>
44+
</template>
45+
46+
<script lang="ts">
47+
export default {
48+
name: 'OverallStatistics',
49+
};
50+
</script>
51+
52+
<script lang="ts" setup>
53+
import { OverallStats } from '../dto/tabListSummary';
54+
import { convertSummaryTimeToString } from '../utils/converter';
55+
56+
const props = defineProps<{
57+
data: OverallStats;
58+
}>();
59+
</script>
60+
61+
<style scoped>
62+
.stats-block {
63+
margin: 5px 35px;
64+
}
65+
66+
.stats-block .row {
67+
display: flex;
68+
flex-direction: row;
69+
justify-content: space-around;
70+
margin: 10px 0;
71+
}
72+
73+
.stats-block .block {
74+
width: 165px;
75+
text-align: center;
76+
}
77+
78+
.stats-block .block .header {
79+
background-color: var(--popup-header);
80+
color: rgb(66, 66, 66);
81+
padding: 5px 5px;
82+
border-radius: 5px;
83+
}
84+
85+
.stats-block .block p {
86+
margin: 2px;
87+
text-align: center;
88+
font-weight: 700;
89+
font-size: 13px;
90+
color: rgb(59, 59, 59);
91+
}
92+
</style>

src/components/TabList.vue

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<template>
22
<div class="no-data" v-if="countOfSites == undefined || countOfSites == 0">No data</div>
33
<div v-else>
4+
<OverallStatistics v-if="isShowOverallStats" :data="dataForOvarallStats" />
45
<DonutChart :time="timeForChart" :labels="sitesForChart" />
56
<TabItemHeader
67
:listType="type"
@@ -25,19 +26,24 @@ import { computed, onMounted, ref } from 'vue';
2526
import TabItem from '../components/TabItem.vue';
2627
import TabItemHeader from '../components/TabItemHeader.vue';
2728
import DonutChart from '../components/DonutChart.vue';
28-
import { injectTabsRepository } from '../repository/inject-tabs-repository';
29+
import OverallStatistics from '../components/OverallStatistics.vue';
2930
import { Tab } from '../entity/tab';
3031
import { SortingBy, TypeOfList } from '../utils/enums';
3132
import { useTodayTabListSummary } from '../compositions/today-tab-list-summary';
3233
import { useAllTabListSummary } from '../compositions/all-tab-list-summary';
3334
import { CurrentTabItem } from '../dto/currentTabItem';
3435
import { todayLocalDate } from '../utils/today';
36+
import { OverallStats } from '../dto/tabListSummary';
3537
3638
const props = defineProps<{
3739
type: TypeOfList;
40+
showAllStats: boolean;
3841
}>();
3942
43+
const isShowOverallStats = computed(() => props.showAllStats && props.type == TypeOfList.All);
44+
4045
const tabs = ref<Tab[]>();
46+
const dataForOvarallStats = ref<OverallStats>();
4147
4248
const timeForChart = ref<number[]>();
4349
const sitesForChart = ref<string[]>();
@@ -46,15 +52,13 @@ const summaryTime = ref<number>();
4652
4753
const countOfSites = computed(() => (tabs.value != undefined ? tabs.value.length : 0));
4854
49-
const firstDay = computed(() => {
50-
if (props.type == TypeOfList.All) return;
51-
});
52-
5355
async function loadList(sortingBy: SortingBy) {
54-
const repo = await injectTabsRepository();
5556
let tabSummary = null;
5657
if (props.type == TypeOfList.Today) tabSummary = await useTodayTabListSummary(sortingBy);
57-
if (props.type == TypeOfList.All) tabSummary = await useAllTabListSummary(sortingBy);
58+
if (props.type == TypeOfList.All) {
59+
tabSummary = await useAllTabListSummary(sortingBy);
60+
dataForOvarallStats.value = tabSummary;
61+
}
5862
5963
if (tabSummary != null) {
6064
tabs.value = tabSummary.tabs;

src/compositions/all-tab-list-summary.ts

Lines changed: 67 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,54 @@
1-
import { TabListSummary } from '../dto/tabListSummary';
2-
import { Tab } from '../entity/tab';
1+
import { ActiveDay, OverallStats } from '../dto/tabListSummary';
2+
import { Tab, TabDay } from '../entity/tab';
33
import { injectTabsRepository } from '../repository/inject-tabs-repository';
44
import { SortingBy } from '../utils/enums';
5+
import { daysBetween } from '../utils/time';
6+
import { todayLocalDate } from '../utils/today';
57

6-
export async function useAllTabListSummary(sortingBy: SortingBy): Promise<TabListSummary> {
8+
export async function useAllTabListSummary(sortingBy: SortingBy): Promise<OverallStats> {
79
const repo = await injectTabsRepository();
810
const unSortedTabs = repo.getTabs();
911
let tabs: Tab[] = [];
1012

13+
const summaryTimeListForToday = unSortedTabs.map(function (tab) {
14+
return tab.days.find(day => day.date === todayLocalDate())!.summary;
15+
});
16+
17+
const todaySummaryTime =
18+
summaryTimeListForToday != undefined && summaryTimeListForToday.length > 0
19+
? summaryTimeListForToday.reduce(function (a, b) {
20+
return a + b;
21+
})
22+
: 0;
23+
1124
tabs = unSortedTabs.sort(function (a: Tab, b: Tab) {
1225
return b.summaryTime - a.summaryTime;
1326
});
1427

15-
tabs = unSortedTabs.sort(function (a: Tab, b: Tab) {
16-
return sortingBy == SortingBy.UsageTime ? b.summaryTime - a.summaryTime : b.counter - a.counter;
28+
let days: TabDay[] = [];
29+
tabs.map(function (tab) {
30+
return tab.days.forEach(function (day) {
31+
const existDay = days.find(x => x.date == day.date);
32+
if (!existDay) days.push(day);
33+
else {
34+
existDay.summary += day.summary;
35+
existDay.counter += day.counter;
36+
}
37+
});
1738
});
1839

40+
days = days.sort(function (a, b) {
41+
return new Date(a.date).valueOf() - new Date(b.date).valueOf();
42+
});
43+
44+
const firstDay = new Date(days[0].date);
45+
const activeDaysTotal = days.length;
46+
47+
if (sortingBy == SortingBy.Sessions)
48+
tabs = unSortedTabs.sort(function (a: Tab, b: Tab) {
49+
return b.counter - a.counter;
50+
});
51+
1952
const summaryTimeList = tabs?.map(function (tab) {
2053
return tab.summaryTime;
2154
});
@@ -31,12 +64,39 @@ export async function useAllTabListSummary(sortingBy: SortingBy): Promise<TabLis
3164
return a + b;
3265
})
3366
: 0;
67+
68+
const averageTimeByActiveDays = Math.round(summaryTime / activeDaysTotal);
69+
const daysTotal = daysBetween(firstDay, new Date(days[days.length - 1].date));
70+
71+
const sortedByTimeDays = days.sort(function (a, b) {
72+
return a.summary - b.summary;
73+
});
74+
75+
const mostActiveDay = sortedByTimeDays[0];
76+
const mostActiveDayObj = fillMostDay(mostActiveDay);
77+
78+
const mostInactiveDay = sortedByTimeDays[sortedByTimeDays.length - 1];
79+
const mostInactiveDayObj = fillMostDay(mostInactiveDay);
3480
return {
35-
tabs,
36-
summaryTime,
81+
firstDay: firstDay,
82+
daysTotal: daysTotal,
83+
activeDaysTotal: activeDaysTotal,
84+
todaySummaryTime: todaySummaryTime,
85+
averageTimeByActiveDays: averageTimeByActiveDays,
86+
mostActiveDay: mostActiveDayObj,
87+
mostInactiveDay: mostInactiveDayObj,
88+
tabs: tabs,
89+
summaryTime: summaryTime,
3790
chart: {
3891
timeForChart,
3992
sitesForChart,
4093
},
4194
};
4295
}
96+
97+
function fillMostDay(mostDat: TabDay): ActiveDay {
98+
return {
99+
date: new Date(mostDat.date),
100+
summaryTime: mostDat.summary,
101+
};
102+
}

src/dto/tabListSummary.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
import { Tab } from '../entity/tab';
22

3+
export interface OverallStats extends TabListSummary {
4+
firstDay: Date;
5+
activeDaysTotal: number;
6+
daysTotal: number;
7+
todaySummaryTime: number;
8+
averageTimeByActiveDays: number;
9+
mostActiveDay: ActiveDay;
10+
mostInactiveDay: ActiveDay;
11+
}
12+
13+
export interface ActiveDay {
14+
date: Date;
15+
summaryTime: number;
16+
}
17+
318
export interface TabListSummary {
419
tabs: Tab[];
520
summaryTime: number;

src/pages/Popup.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,10 @@
2525
<div class="slider"><div class="indicator"></div></div>
2626
<div class="content">
2727
<section>
28-
<TabList :type="TypeOfList.Today" />
28+
<TabList :type="TypeOfList.Today" :showAllStats="false" />
2929
</section>
3030
<section>
31-
<TabList :type="TypeOfList.All" />
31+
<TabList :type="TypeOfList.All" :showAllStats="true" />
3232
</section>
3333
<section>
3434
<h2>Shipping</h2>

src/utils/time.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,14 @@ export function getNextTimeOfDay(timeOfDay: number): number {
77
const todaysTime = getToday() + timeOfDay;
88
return todaysTime > Date.now() ? todaysTime : todaysTime + DAY_MINUTES;
99
}
10+
11+
export function treatAsUTC(date: Date): Date {
12+
const result = new Date(date);
13+
result.setMinutes(result.getMinutes() - result.getTimezoneOffset());
14+
return result;
15+
}
16+
17+
export function daysBetween(startDate: Date, endDate: Date): number {
18+
const millisecondsPerDay = 24 * 60 * 60 * 1000;
19+
return (treatAsUTC(endDate).valueOf() - treatAsUTC(startDate).valueOf()) / millisecondsPerDay + 1;
20+
}

0 commit comments

Comments
 (0)