Skip to content

Commit

Permalink
Merge pull request #29 from atiratree/filter-by-group
Browse files Browse the repository at this point in the history
filter by group to make the generation more performant
  • Loading branch information
atiratree authored Oct 10, 2024
2 parents 3545335 + aa32b23 commit 6bb35a1
Show file tree
Hide file tree
Showing 25 changed files with 138 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/Billing/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function include(filename) {
* @return {Array<Object>} array with name of all clients
*/
function getClients() {
return Utils.sort(Utils.convertObjectsToArrayByProperty(Utils.findClients(), 'name'));
return Utils.sort(Utils.convertObjectsToArrayByProperty(Utils.findClients(['name']), 'name'));
}

/**
Expand Down
7 changes: 5 additions & 2 deletions src/Billing/WriteBilling.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@
* @return {string} url of new spreadsheet
*/
function createBilling(from, to, client) {
const spreadsheetData = Utils.extractAllSpreadsheetData(from, to);
const groups = Utils.convertObjectsToArrayByProperty(Utils.findGroupClients(['group'], { name: client }), 'group');
const groupSet = new Set(groups);
const spreadsheetData = Utils.extractAllSpreadsheetData(from, to, groupSet);
const ss = Utils.createSpreadsheet({
type: 'Fakturace'
type: 'Fakturace',
details: client
});
const sheet = ss.getActiveSheet();

Expand Down
2 changes: 1 addition & 1 deletion src/Billing/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/CalendarAndFilesScheduler/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/ConsistencyChecker/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Create/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Delete/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/EmailSender/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions src/PdfBackuper/Code.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function doGet(e) {
function processForm(formObject) {
try {
var errorMsg = {fromErr:'',toErr:''};
var from,to;
var from, to, group, groupHumanReadableName;

from = Utils.validate(errorMsg,formObject.fromBox,{
actions:['validateDate',],
Expand All @@ -55,9 +55,24 @@ function processForm(formObject) {
errorMsg.fromErr = '*datum od je větší než datum do';
}

group = formObject.selectBox;
if (group == null) {
group = '';
}
if (group != '') {
group = Utils.validate(errorMsg,formObject.selectBox,{
actions:['notUnique'],
actionObjs:[{uniqueArray:getGroups()}],
actionErrors:[{selectErr:'*zadejte validní skupinu'}]
});
groupHumanReadableName = group;
} else {
groupHumanReadableName = "Všechny Skupiny";
}

if (Utils.isObjErrorFree(errorMsg)) {
errorMsg.success = backupToPdf(from,to);
Utils.log('Backuped to pdf in time span ' + from + ' - ' + to );
errorMsg.success = backupToPdf(from,to, group, groupHumanReadableName);
Utils.log('Backuped to pdf for group ' + groupHumanReadableName + ' in time span ' + from + ' - ' + to);
}

return errorMsg;
Expand Down
12 changes: 10 additions & 2 deletions src/PdfBackuper/PdfBackuper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
function backupToPdf (from, to) {
function backupToPdf (from, to, group, groupHumanReadableName) {
groupSet = null;
if (group != '') {
groupSet = new Set([group])
}

const time = new Date().toISOString();
const ROZPIS = 'Rozpis'

const folder = DriveApp.createFolder('Záloha_' + time);
const folder = DriveApp.createFolder('Záloha_' + time + '_' + groupHumanReadableName);

const tmpSS = SpreadsheetApp.create('Tmp');
const tmpSSId = tmpSS.getId();
Expand All @@ -14,6 +19,9 @@ function backupToPdf (from, to) {
Utils.findFiles([], {
type: ROZPIS
}).filter(function (file) {
if (groupSet != null && !groupSet.has(file.group)) {
return false;
}
return Utils.isWeekWithinDates(from, to, file.year, file.week);
}).forEach(function (file) {

Expand Down
7 changes: 7 additions & 0 deletions src/PdfBackuper/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

/**
* @return {Array<Object>} array with name of all groups
*/
function getGroups() {
return Utils.sort(Utils.convertObjectsToArrayByProperty(Utils.findGroups(['group']), 'group'));
}

/**
* Creates presentable HTML for a browser
* *cannot be run from library, becaouse of filename
Expand Down
2 changes: 1 addition & 1 deletion src/PdfBackuper/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/PdfBackuper/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
<input id='toBox' type='date' name='toBox' min='1900-01-01' required='true' >
<label id='toErr' class='error' for='toBox' hidden='true'></label>
</p>
<p>
<label for='selectBox'>Skupina</label>
<br>
<select id='selectBox' name='selectBox'>
<option value="">Všechny Skupiny</option>
</select>
<label id='selectErr' class='error' for='selectBox' hidden='true'></label>
</p>
<p id='submit'>
<input class='button' type='submit' value='Zálohuj do PDF'>
</p>
Expand All @@ -38,3 +46,4 @@
</div>
</div>
<?!= include('javascript'); ?>
<?!= include('pdfbackuper-js'); ?>
9 changes: 9 additions & 0 deletions src/PdfBackuper/pdfbackuper-js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Javascript for billing which fills form with clients-->
<script>
google.script.run.withSuccessHandler(function(obj) {
var options = $('#selectBox');
$.each(obj, function() {
options.append($('<option />').val(this).text(this));
});
}).getGroups();
</script>
2 changes: 1 addition & 1 deletion src/RenameGroup/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/SheetRedirect/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 18 additions & 3 deletions src/Statistics/Stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
function process(formObject) {
var errorMsg = {fromErr:'',toErr:''};
var from,to;
var from, to, group, groupHumanReadableName;

from = Utils.validate(errorMsg,formObject.fromBox,{
actions:['validateDate',],
Expand All @@ -30,9 +30,24 @@ function process(formObject) {
errorMsg.fromErr = '*datum od je větší než datum do';
}

group = formObject.selectBox;
if (group == null) {
group = '';
}
if (group != '') {
group = Utils.validate(errorMsg,formObject.selectBox,{
actions:['notUnique'],
actionObjs:[{uniqueArray:getGroups()}],
actionErrors:[{selectErr:'*zadejte validní skupinu'}]
});
groupHumanReadableName = group;
} else {
groupHumanReadableName = "Všechny Skupiny";
}

if(Utils.isObjErrorFree(errorMsg)) {
errorMsg.success = createStatistics(from,to);
Utils.log('Generated stats in time span ' + from + ' - ' + to );
errorMsg.success = createStatistics(from,to, group, groupHumanReadableName);
Utils.log('Generated stats for group ' + groupHumanReadableName + ' in time span ' + from + ' - ' + to );
}

return errorMsg;
Expand Down
7 changes: 7 additions & 0 deletions src/Statistics/Utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ function include(filename) {
return HtmlService.createHtmlOutputFromFile(filename).getContent();
}

/**
* @return {Array<Object>} array with name of all groups
*/
function getGroups() {
return Utils.sort(Utils.convertObjectsToArrayByProperty(Utils.findGroups(['group']), 'group'));
}

/**
* Creates presentable HTML for a browser
* *cannot be run from library, becaouse of filename
Expand Down
27 changes: 18 additions & 9 deletions src/Statistics/WriteStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@
* Creates statistics spreadsheet in user's google drive and generates data into it
*
* @param from from which day stats are going to be created
* @param to to which day stats are going to be created
* @param to to which day stats are going to be created
* @param groups stats are going to be created only for this group if not empty
* @param groupHumanReadableName group name or an identifier for all groups
* @return {string} url of new spreadsheet
*/
function createStatistics(from, to) {
let spreadsheetData = Utils.extractAllSpreadsheetData(from, to); // can throw timeout
function createStatistics(from, to, group, groupHumanReadableName) {
groupSet = null;
if (group != '') {
groupSet = new Set([group])
}

let spreadsheetData = Utils.extractAllSpreadsheetData(from, to, groupSet); // can throw timeout
const ss = Utils.createSpreadsheet({
type: 'Statistika'
type: 'Statistika',
details: groupHumanReadableName
});
const clientsSheet = ss.getActiveSheet();
const clientsSheet2 = ss.insertSheet('Klienti Počet návštěv');
Expand All @@ -25,9 +33,9 @@ function createStatistics(from, to) {
return !eventsMap[item['event']];
});

writeStats(spreadsheetData, clientsSheet, 'event', from, to, false);
writeStats(spreadsheetData, clientsSheet2, 'event', from, to, true);
writeStats(spreadsheetData, assistantsSheet, 'employee', from, to, false);
writeStats(spreadsheetData, clientsSheet, 'event', from, to, false, groupHumanReadableName);
writeStats(spreadsheetData, clientsSheet2, 'event', from, to, true, groupHumanReadableName);
writeStats(spreadsheetData, assistantsSheet, 'employee', from, to, false, groupHumanReadableName);
return ss.getUrl();
}

Expand All @@ -40,8 +48,9 @@ function createStatistics(from, to) {
* @param from from which data to write stats
* @param to to which data to write stats
* @param onlyCount measure occurences count instead of duration
* @param groupHumanReadableName group name or an identifier for all groups
*/
function writeStats(spreadsheetData, sheet, type, from, to, onlyCount) {
function writeStats(spreadsheetData, sheet, type, from, to, onlyCount, groupHumanReadableName) {
const months = Utils.getMonthsNames();
// stats = {
// "John": {
Expand Down Expand Up @@ -133,7 +142,7 @@ function writeStats(spreadsheetData, sheet, type, from, to, onlyCount) {
color: '#E2F3FF'
});
}
writeToCell(sheet, sortedFoundNames.length + 8, 1, '* Statistika v časovém období: ' + Utils.getFormatedDate(from, true) + ' - ' + Utils.getFormatedDate(
writeToCell(sheet, sortedFoundNames.length + 8, 1, '* Statistika pro ' + groupHumanReadableName + ' v časovém období: ' + Utils.getFormatedDate(from, true) + ' - ' + Utils.getFormatedDate(
to, true));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Statistics/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/Statistics/main.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@
<input id='toBox' type='date' name='toBox' min='1900-01-01' required='true' >
<label id='toErr' class='error' for='toBox' hidden='true'></label>
</p>
<p>
<label for='selectBox'>Skupina</label>
<br>
<select id='selectBox' name='selectBox'>
<option value="">Všechny Skupiny</option>
</select>
<label id='selectErr' class='error' for='selectBox' hidden='true'></label>
</p>
<p id='submit'>
<input class='button' type='submit' value='Zpracuj'>
</p>
Expand All @@ -38,3 +46,4 @@
</div>
</div>
<?!= include('javascript'); ?>
<?!= include('statistics-js'); ?>
9 changes: 9 additions & 0 deletions src/Statistics/statistics-js.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<!-- Javascript for billing which fills form with clients-->
<script>
google.script.run.withSuccessHandler(function(obj) {
var options = $('#selectBox');
$.each(obj, function() {
options.append($('<option />').val(this).text(this));
});
}).getGroups();
</script>
2 changes: 1 addition & 1 deletion src/TableScript/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Update/appsscript.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 6bb35a1

Please sign in to comment.