Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #24 handle day unit #35

Merged
merged 1 commit into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,21 @@

This [action](./action.yml) generates periodic umami reports into a given file, and action outputs.

Accepted periods are: 1h, 1d, 7d, 30d, 31d.
Accepted periods are: 1h, 1d, 1w, 1m.

## Inputs

| input name | required | description |
|------------------------|----------|------------------------------------|
| `umami-server` | yes | Umami server instance (*). |
| `umami-user` | yes | Umami API user. Default `"admin"`. |
| `umami-password` | yes | Umami API password. |
| `umami-site-domain` | no | Umami site domain name (*). |
| `umami-report-file` | no | Umami report file to generate. |
| `umami-report-content` | no | Report content to generate (*). |
| `umami-period` | no | (main) Report data/analysis period (*). |
| `umami-unit` | no | (main) Report interval unit (*). |
| `umami-tz` | no | (main) Report date time timezone (*). |
| input name | required | description |
|------------------------|----------|-----------------------------------------|
| `umami-server` | yes | Umami server instance (*). |
| `umami-user` | yes | Umami API user. Default `"admin"`. |
| `umami-password` | yes | Umami API password. |
| `umami-site-domain` | no | Umami site domain name (*). |
| `umami-report-file` | no | Umami report file to generate. |
| `umami-report-content` | no | Report content to generate (*). |
| `umami-period` | no | (main) Report data/analysis period (*). |
| `umami-unit` | no | (main) Report interval unit (*). |
| `umami-tz` | no | (main) Report date time timezone (*). |

legend*:
- [Umami API](https://umami.is/docs/api) login expected to be available at `https://<umami-server>/api/auth/login`.
Expand Down Expand Up @@ -101,9 +101,12 @@ npm manual.js

### Services or activated bots

| badge | name | description |
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------------------------------|:-----------------------------------------------------------------------------------|
| [![scheduled npm audit](https://github.com/boly38/action-umami-report/actions/workflows/audit.yml/badge.svg)](https://github.com/boly38/action-umami-report/actions/workflows/audit.yml) | Github actions | Continuous vulnerability audit.
| [<img src="https://cdn.icon-icons.com/icons2/2148/PNG/512/houndci_icon_132320.png" width="100">](https://houndci.com/) | [Houndci](https://houndci.com/) | JavaScript automated review (configured by `.hound.yml`) |
| [![Automated Release Notes by gren](https://img.shields.io/badge/%F0%9F%A4%96-release%20notes-00B2EE.svg)](https://github-tools.github.io/github-release-notes/) | [gren](https://github.com/github-tools/github-release-notes) | [Release notes](https://github.com/boly38/action-umami-report/releases) automation |
- [Github actions](https://github.com/features/actions) - Continuous vulnerability audit.<br/>
[![scheduled npm audit](https://github.com/boly38/action-umami-report/actions/workflows/audit.yml/badge.svg)](https://github.com/boly38/action-umami-report/actions/workflows/audit.yml)

- [Houndci](https://houndci.com/) - JavaScript automated review (configured by [`.hound.yml`](./.hound.yml)).<br/>
[<img src="https://cdn.icon-icons.com/icons2/2148/PNG/512/houndci_icon_132320.png" width="100">](https://houndci.com/)

- [gren](https://github.com/github-tools/github-release-notes) - [Release notes](https://github.com/boly38/action-umami-report/releases) automation.<br/>
[![Automated Release Notes by gren](https://img.shields.io/badge/%F0%9F%A4%96-release%20notes-00B2EE.svg)](https://github-tools.github.io/github-release-notes/)

4 changes: 2 additions & 2 deletions lib/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ class Action {


static async produceReport(umamiSite, umamiSiteStats, sitePageViews = null, siteEvents = null, siteMetricsUrl = null,
outputFile = null, reportContent = 'pageviews|events|urls', period = '24h') {
outputFile = null, reportContent = 'pageviews|events|urls', period = '24h', unit = 'hour') {
//~~ generate umami report content
const generator = new ReportGenerator(umamiSite, reportContent, period, umamiSiteStats, sitePageViews, siteEvents, siteMetricsUrl);
const generator = new ReportGenerator(umamiSite, reportContent, period, unit, umamiSiteStats, sitePageViews, siteEvents, siteMetricsUrl);
const umamiOneLineReport = generator.oneLineReport();
const umamiReport = generator.detailedReport();

Expand Down
7 changes: 4 additions & 3 deletions lib/reportGenerator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ const ENUMERATION_LIMIT = 10;

class ReportGenerator {

constructor(umamiSite, reportContent = 'pageviews|events|urls', period = '24h', umamiSiteStats = null, sitePageViews = null, siteEvents = null, siteMetricsUrl = null) {
constructor(umamiSite, reportContent = 'pageviews|events|urls', period = '24h', unit = 'hour', umamiSiteStats = null, sitePageViews = null, siteEvents = null, siteMetricsUrl = null) {
this.site = umamiSite;
this.siteStats = umamiSiteStats;
this.sitePageViews = sitePageViews;
this.siteEvents = siteEvents;
this.siteMetricsUrl = siteMetricsUrl;
this.reportContent = reportContent;
this.period = period;
this.unit = unit;
this.reportDateTime = dayjs().format('DD/MM/YYYY HH:mm')
}

Expand Down Expand Up @@ -74,9 +75,9 @@ class ReportGenerator {
report += `events:\n`;
var lastTime = '';
this.siteEvents.forEach( event => {
const eventDateTime = event.t.substring(11);
const eventDateTime = (this.period === '24h') ? event.t.substring(11) : event.t.substring(5);
if (eventDateTime !== lastTime) {
report += ` - ${eventDateTime} ${event.y}x [${event.x}]`;
report += `\n - ${eventDateTime} ${event.y}x [${event.x}]`;
} else {
report += `, ${event.y}x [${event.x}]`;
}
Expand Down
15 changes: 11 additions & 4 deletions manual.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ const UMAMI_REPORT_FILE = process.env.UMAMI_REPORT_FILE || "umamiReport.txt";
const UMAMI_REPORT_CONTENT = process.env.UMAMI_REPORT_CONTENT || "pageviews|events|urls";
const rethrow = (err) => {throw err;}

const actionUmamiReport = async function() {
try {
class Manual {

getOptions() {
if (UMAMI_SERVER === null) {
throw "please setup your environment UMAMI_SERVER, UMAMI_USER, UMAMI_PASSWORD, UMAMI_SITE_DOMAIN"
}
Expand All @@ -25,13 +26,19 @@ const actionUmamiReport = async function() {
options.period = '24h';
options.unit = 'hour';
options.tz = 'Europe/Paris';
return options;
}

async report(options = {}) {
try {
const reportResult = await action.umamiReport(options).catch(rethrow);
if ('targetFile' in reportResult) {
console.info(`Generated : ${reportResult.targetFile}`);
}
} catch (error) {
console.info(`ERROR: ${error}`)
}
}
}

actionUmamiReport();
}
export default Manual;
8 changes: 8 additions & 0 deletions manual_1m_day.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Manual from './manual.js';

const manual = new Manual();

var options = manual.getOptions()
options.period = '1month';
options.unit = 'day';
manual.report(options);
8 changes: 8 additions & 0 deletions manual_1m_hour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Manual from './manual.js';

const manual = new Manual();

var options = manual.getOptions()
options.period = '1month';
options.unit = 'hour';
manual.report(options);
8 changes: 8 additions & 0 deletions manual_1w_day.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Manual from './manual.js';

const manual = new Manual();

var options = manual.getOptions()
options.period = '1week';
options.unit = 'day';
manual.report(options);
8 changes: 8 additions & 0 deletions manual_1w_hour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import Manual from './manual.js';

const manual = new Manual();

var options = manual.getOptions()
options.period = '1week';
options.unit = 'hour';
manual.report(options);
5 changes: 5 additions & 0 deletions manual_24h_hour.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import Manual from './manual.js';

const manual = new Manual();

manual.report(manual.getOptions());