Browse Source

earnings reports and ioserver keepalive tweaking

develop
Rob Colbert 12 months ago
parent
commit
2790602d8b
  1. 63
      app/services/report.js
  2. 16
      app/views/home.pug
  3. 17
      app/views/report/components/weekly-summary.pug
  4. 14
      app/views/report/dashboard.pug
  5. 6
      lib/site-ioserver.js

63
app/services/report.js

@ -21,31 +21,56 @@ export default class ReportService extends SiteService {
} }
async getWeeklyEarnings (user) { async getWeeklyEarnings (user) {
const { client: clientService } = this.dtp.services;
const NOW = new Date(); const NOW = new Date();
const dateStart = this.startOfWeek(NOW); const dateStart = this.startOfWeek(NOW);
const dateEnd = dayjs(dateStart).add(1, 'week').toDate(); const dateEnd = dayjs(dateStart).add(1, 'week').toDate();
this.log.debug('computing weekly earnings', { dateStart, dateEnd }); this.log.debug('computing weekly earnings', { dateStart, dateEnd });
/* const data = await TaskSession.aggregate([
* I'm sure there's some beautiful way to do this using aggregation but I {
* don't care at all (and won't) until aggregation becomes a usable API. $match: {
*/ user: user._id,
const response = { sessionCount: 0, duration: 0, billable: 0 }; $and: [
await TaskSession { created: { $gte: dateStart } },
.find({ { finished: { $lt: dateEnd } },
user: user._id, ],
$and: [ },
{ created: { $gte: dateStart } }, },
{ finished: { $lt: dateEnd } }, {
], $group: {
}) _id: { project: '$project' },
.cursor() sessionCount: { $sum: 1 },
.eachAsync(async (session) => { duration: { $sum: '$duration' },
response.sessionCount += 1; billable: {
response.duration += session.duration; $sum: {
response.billable += session.hourlyRate * (session.duration / 60 / 60); $multiply: [
}); '$hourlyRate',
{ $divide: ['$duration', 3600 ] },
],
},
},
},
},
{
$project: {
_id: 0,
project: '$_id.project',
sessionCount: '$sessionCount',
duration: '$duration',
billable: '$billable',
},
},
]);
const response = await TaskSession.populate(data, [
{
path: 'project',
populate: clientService.populateClientProject,
},
]);
return response; return response;
} }

16
app/views/home.pug

@ -2,21 +2,13 @@ extends layout/main
block view-content block view-content
include task/components/grid include task/components/grid
include report/components/weekly-summary
section.uk-section.uk-section-secondary.uk-section-small section.uk-section.uk-section-muted.uk-section-small
.uk-container .uk-container
div(uk-grid).uk-flex-between +renderWeeklySummaryReport(weeklyEarnings)
.uk-width-auto
div sessions
.uk-text-large.uk-text-bold= formatCount(weeklyEarnings.sessionCount)
.uk-width-auto
div time worked
.uk-text-large.uk-text-bold= numeral(weeklyEarnings.duration).format('0:00:00')
.uk-width-auto
div billable
.uk-text-large.uk-text-bold= numeral(weeklyEarnings.billable).format('$0,0.00')
section.uk-section.uk-section-default section.uk-section.uk-section-default.uk-section-small
.uk-container .uk-container
+renderTaskGrid( +renderTaskGrid(
taskGrid.pendingTasks, taskGrid.pendingTasks,

17
app/views/report/components/weekly-summary.pug

@ -0,0 +1,17 @@
mixin renderWeeklySummaryReport (data)
table.uk-table.uk-table-small.uk-table-justify.no-select
thead
tr
th Project
th Client
th Sessions
th Time Worked
th Billable
tbody
each row in data
tr
td.uk-table-expand=row.project.name
td= row.project.client.name
td= formatCount(row.sessionCount)
td= numeral(row.duration).format('0:00:00')
td= numeral(row.billable).format('$0,0.00')

14
app/views/report/dashboard.pug

@ -1,16 +1,8 @@
extends ../layout/main extends ../layout/main
block view-content block view-content
include components/weekly-summary
section.uk-section.uk-section-default.uk-section section.uk-section.uk-section-default.uk-section
.uk-container .uk-container
+renderWeeklySummaryReport(weeklyEarnings)
div(uk-grid).uk-flex-between
.uk-width-auto
.uk-text-bold.uk-text-small Sessions
div= formatCount(weeklyEarnings.sessionCount)
.uk-width-auto
.uk-text-bold.uk-text-small Hours
div= numeral(weeklyEarnings.duration).format('0:00:00')
.uk-width-auto
.uk-text-bold.uk-text-small Billable
div= numeral(weeklyEarnings.billable).format('$0,0.00')

6
lib/site-ioserver.js

@ -50,7 +50,11 @@ export class SiteIoServer extends SiteCommon {
this.adapterSubClient = this.dtp.redis.duplicate(); this.adapterSubClient = this.dtp.redis.duplicate();
this.adapter = createAdapter(this.adapterPubClient, this.adapterSubClient); this.adapter = createAdapter(this.adapterPubClient, this.adapterSubClient);
this.io = new Server(httpServer, { adapter: this.adapter, transports }); this.io = new Server(httpServer, {
adapter: this.adapter, transports,
pingInterval: 5000,
pingTimeout: 3000,
});
this.io.adapter(this.adapter); this.io.adapter(this.adapter);
this.io.on('connection', this.onSocketConnect.bind(this)); this.io.on('connection', this.onSocketConnect.bind(this));

Loading…
Cancel
Save