-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Antoine Jeanneney
committed
Jun 28, 2024
1 parent
fc8db0d
commit 7dbfa58
Showing
5 changed files
with
77 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import { buildBackend } from '@label/backend'; | ||
import { parametersHandler } from '../lib/parametersHandler'; | ||
|
||
(async () => { | ||
const { settings } = await parametersHandler.getParameters(); | ||
const backend = buildBackend(settings); | ||
|
||
await backend.runScript( | ||
() => backend.scripts.promptDailyStats.run(settings), | ||
backend.scripts.promptDailyStats.option, | ||
); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
packages/generic/backend/src/app/scripts/promptDailyStats.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { logger } from '../../utils'; | ||
import { ressourceFilterType, settingsType } from '@label/core'; | ||
import { userService } from '../../modules/user'; | ||
import { fetchAggregatedStatisticsAccordingToFilter } from '../../modules/statistic/service/fetchAggregatedStatisticsAccordingToFilter'; | ||
|
||
export { promptDailyStats }; | ||
|
||
async function promptDailyStats(settings: settingsType) { | ||
logger.log({ operationName: 'TESTpromptDailyStats', msg: 'START' }); | ||
|
||
const activeUsers = await userService.fetchWorkingUsers(); | ||
|
||
const endDate = Date.now(); | ||
const startDate = endDate - 24 * 60 * 60 * 1000; | ||
|
||
for (const user of activeUsers) { | ||
const filter: ressourceFilterType = { | ||
mustHaveSurAnnotations: false, | ||
mustHaveSubAnnotations: false, | ||
startDate, | ||
endDate, | ||
userId: user._id, | ||
importer: undefined, | ||
jurisdiction: undefined, | ||
publicationCategory: undefined, | ||
route: undefined, | ||
source: undefined, | ||
}; | ||
|
||
try { | ||
const aggregatedStats = await fetchAggregatedStatisticsAccordingToFilter( | ||
filter, | ||
settings, | ||
); | ||
logger.log({ | ||
operationName: 'TESTuserDailyStats', | ||
msg: `dailyStats of ${user.name}`, | ||
data: { userName: user.name, ...aggregatedStats }, | ||
}); | ||
} catch (error) { | ||
logger.error({ | ||
operationName: 'TESTpromptDailyStats', | ||
msg: `Error fetching stats: ${error}`, | ||
}); | ||
} | ||
} | ||
|
||
logger.log({ operationName: 'TESTpromptDailyStats', msg: 'END' }); | ||
} |