Skip to content
This repository was archived by the owner on Mar 30, 2024. It is now read-only.

Commit d378769

Browse files
committed
Rename Graphs && Optimize get_browser
1 parent 88aaec9 commit d378769

File tree

12 files changed

+198
-230
lines changed

12 files changed

+198
-230
lines changed

Dockerfile

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
FROM kimbtechnologies/php_nginx:latest
22

3-
# copy php files, nginx conf and startup scripts
4-
COPY --chown=www-data:www-data ./php/ /php-code/
5-
COPY --chown=www-data:www-data ./start/ /start/
3+
# enable get_browser() in PHP
4+
RUN mkdir /start/ \
5+
&& curl -L https://browscap.org/stream?q=Lite_PHP_BrowsCapINI -o /start/php_browscap.ini \
6+
&& echo "browscap = /start/php_browscap.ini" > /usr/local/etc/php/conf.d/enable_browscap.ini
7+
8+
# config files, changed seldom
69
COPY ./nginx.conf /etc/nginx/more-server-conf.conf
710
COPY ./startup-before.sh /
8-
COPY ./VERSION /php-code/VERSION
11+
COPY ./start/* /start/
912

10-
RUN curl -L https://browscap.org/stream?q=Lite_PHP_BrowsCapINI -o /start/lite_php_browscap.ini \
11-
&& echo "browscap = /start/lite_php_browscap.ini" > /usr/local/etc/php/conf.d/enable_browscap.ini
13+
# php files, changed more often
14+
COPY ./php/ /php-code/
15+
COPY ./VERSION /php-code/VERSION

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
latest
2-
0.3.3
2+
0.3.4
33
0.3
44
0

nginx.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,8 @@ error_page 403 /index.php?err=403;
44
location ~ ^/(data|core){
55
deny all;
66
return 403;
7+
}
8+
9+
location /VERSION {
10+
add_header "Content-Type" "text/plain; charset=utf-8";
711
}

php/core/Login.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function sessionLogin(string $group, string $token) : void {
5252
if( $sid !== false ){
5353
$this->logUserIn($group);
5454
$this->groupList->setValue([$group, 'sessions', $sid, 'used'], time());
55+
$this->groupList->setValue([$group, 'sessions', $sid, 'browseros'], Utilities::getBrowserOS());
5556
return;
5657
}
5758
}

php/core/Utilities.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ public static function deleteDirRecursive(string $dir) : bool {
8888

8989
public static function getBrowserOS() : string {
9090
$b = get_browser();
91-
return $b->browser . ' ' . $b->version . ' on ' . $b->platform;
91+
if( $b->platform === "MacOSX"){
92+
$b->platform = "mac OS";
93+
}
94+
return $b->browser . ($b->version === "0.0" ? '' : ' ' . $b->version) . ' on ' . $b->platform;
9295
}
9396

9497
}

php/load/bootstrap.min.css

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

php/load/graphs/BarDailyWork.js

Lines changed: 0 additions & 130 deletions
This file was deleted.

php/load/graphs/BarDays.js

Lines changed: 74 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,39 +5,66 @@ function createGraph(combiData, plainData, singleDayData, canvas){
55
* The function should return the ChartJS object.
66
*/
77

8-
var allCategories = []
8+
function getLabelFromTimestamp(t) {
9+
let date = new Date(t * 1000);
10+
let day = (date.getDate() > 9 ? '' : '0') + date.getDate();
11+
let month = (date.getMonth() + 1 > 9 ? '' : '0') + (date.getMonth() + 1);
12+
13+
return `${day}.${month}.${date.getFullYear()}`;
14+
}
15+
16+
// get time span and all categories
17+
var minDate = Number.MAX_SAFE_INTEGER;
18+
var maxDate = Number.MIN_SAFE_INTEGER;
19+
var allCategories = {}
20+
var allNames = {}
921
plainData.forEach(data => {
10-
if( !allCategories.includes(data.category) ) {
11-
allCategories.push(data.category)
22+
if( data.begin < minDate ){
23+
minDate = data.begin;
24+
}
25+
if( data.end > maxDate ){
26+
maxDate = data.end;
27+
}
28+
if( !allCategories.hasOwnProperty(data.category)){
29+
allCategories[data.category] = 0;
30+
}
31+
if( !allNames.hasOwnProperty(data.name)){
32+
allNames[data.name] = 0;
1233
}
1334
});
14-
var catsColumn = allCategories.length === 1 ? 'name' : 'category';
35+
if(Object.keys(allCategories).length === 1){
36+
var catsColumn = 'name';
37+
var allCats = allNames;
38+
}
39+
else{
40+
var catsColumn = 'category';
41+
var allCats = allCategories;
42+
}
1543

16-
var dayMap = {
17-
0:6,
18-
1:0,
19-
2:1,
20-
3:2,
21-
4:3,
22-
5:4,
23-
6:5,
44+
// fill (empty) categories in each day
45+
let plotdata = {};
46+
let plotdataLabels = [];
47+
for( let timestamp = minDate; timestamp <= maxDate; timestamp += 86400){
48+
let label = getLabelFromTimestamp(timestamp);
49+
plotdata[label] = Object.assign({}, allCats);
50+
plotdataLabels.push(label)
2451
}
25-
var plotdata = {}
26-
plainData.forEach( (v) => {
27-
var day = dayMap[new Date(v.begin*1000).getDay()];
28-
if( !plotdata.hasOwnProperty(v[catsColumn])){
29-
plotdata[v[catsColumn]] = []
30-
for(var d = 0; d < 7; d++){
31-
plotdata[v[catsColumn]][d] = 0;
32-
}
33-
}
34-
plotdata[v[catsColumn]][day] += v.duration;
52+
let lastLabel = getLabelFromTimestamp(maxDate);
53+
if( !plotdata.hasOwnProperty(lastLabel)){
54+
plotdata[lastLabel] = Object.assign({}, allCats);
55+
plotdataLabels.push(lastLabel)
56+
}
57+
58+
// fill with data
59+
plainData.forEach(data => {
60+
plotdata[getLabelFromTimestamp(data.begin)][data[catsColumn]] += data.duration;
3561
});
3662

37-
Object.keys(plotdata).forEach(function(category) {
38-
for(var d = 0; d < 7; d++){
39-
plotdata[category][d] = Math.round((plotdata[category][d]/3600) * 100) / 100;
40-
}
63+
// convert to hours
64+
Object.keys(plotdata).forEach(function(label) {
65+
Object.keys(plotdata[label]).forEach(function(category) {
66+
plotdata[label][category] = Math.round((plotdata[label][category] / 3600) * 100) / 100;
67+
});
4168
});
4269

4370
/**
@@ -48,19 +75,31 @@ function createGraph(combiData, plainData, singleDayData, canvas){
4875
*/
4976
const baseColors = ['#4E79A7', '#A0CBE8', '#F28E2B', '#FFBE7D', '#59A14F', '#8CD17D', '#B6992D', '#F1CE63', '#499894', '#86BCB6', '#E15759', '#FF9D9A', '#79706E', '#BAB0AC', '#D37295', '#FABFD2', '#B07AA1', '#D4A6C8', '#9D7660', '#D7B5A6'];
5077

78+
var categoryDatasetIdMap = {};
5179
var chartData = {
52-
labels : ['Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday'],
80+
labels : plotdataLabels,
5381
datasets: []
5482
};
55-
Object.keys(plotdata).forEach( (category, index) => {
56-
chartData.datasets.push({
57-
label : category,
58-
backgroundColor: baseColors[index % baseColors.length],
59-
data: plotdata[category]
83+
84+
var datasetIndex = 0;
85+
plotdataLabels.forEach(function(label) {
86+
Object.keys(plotdata[label]).forEach(function(category) {
87+
if(!categoryDatasetIdMap.hasOwnProperty(category)){
88+
categoryDatasetIdMap[category] = datasetIndex;
89+
chartData.datasets.push({
90+
label : category,
91+
backgroundColor: baseColors[datasetIndex % baseColors.length],
92+
data: []
93+
});
94+
datasetIndex++;
95+
}
96+
chartData.datasets[categoryDatasetIdMap[category]].data.push(
97+
plotdata[label][category]
98+
);
6099
});
61-
})
100+
});
62101

63-
var config = {
102+
let config = {
64103
type: 'bar',
65104
data: chartData,
66105
options: {
@@ -86,5 +125,6 @@ function createGraph(combiData, plainData, singleDayData, canvas){
86125
}
87126
}
88127
};
128+
89129
return new Chart(canvas, config);
90130
}

0 commit comments

Comments
 (0)