-
-
Notifications
You must be signed in to change notification settings - Fork 656
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR takes the project status API a step further by adding the capability of providing a date to control the selection. We are currently making calculations based on a gliding 30 day window, updated once a day. The initial database structure and method for updating the UI is outlined in this PR.
- Loading branch information
1 parent
b80e84b
commit d8a250d
Showing
19 changed files
with
583 additions
and
54 deletions.
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
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,52 @@ | ||
import { Knex } from 'knex'; | ||
import { Logger, LogProvider } from '../logger'; | ||
|
||
import metricsHelper from '../util/metrics-helper'; | ||
import { DB_TIME } from '../metric-events'; | ||
import EventEmitter from 'events'; | ||
import { IProjectStats } from 'lib/services/project-service'; | ||
import { IProjectStatsStore } from 'lib/types/stores/project-stats-store-type'; | ||
|
||
const TABLE = 'project_stats'; | ||
|
||
class ProjectStatsStore implements IProjectStatsStore { | ||
private db: Knex; | ||
|
||
private logger: Logger; | ||
|
||
private timer: Function; | ||
|
||
constructor(db: Knex, eventBus: EventEmitter, getLogger: LogProvider) { | ||
this.db = db; | ||
this.logger = getLogger('project-stats-store.ts'); | ||
this.timer = (action) => | ||
metricsHelper.wrapTimer(eventBus, DB_TIME, { | ||
store: 'project_stats', | ||
action, | ||
}); | ||
} | ||
|
||
async updateProjectStats( | ||
projectId: string, | ||
status: IProjectStats, | ||
): Promise<void> { | ||
await this.db(TABLE) | ||
.insert({ | ||
avg_time_to_prod_current_window: | ||
status.avgTimeToProdCurrentWindow, | ||
avg_time_to_prod_past_window: status.avgTimeToProdPastWindow, | ||
project: projectId, | ||
features_created_current_window: status.createdCurrentWindow, | ||
features_created_past_window: status.createdPastWindow, | ||
features_archived_current_window: status.archivedCurrentWindow, | ||
features_archived_past_window: status.archivedPastWindow, | ||
project_changes_current_window: | ||
status.projectActivityCurrentWindow, | ||
project_changes_past_window: status.projectActivityPastWindow, | ||
}) | ||
.onConflict('project') | ||
.merge(); | ||
} | ||
} | ||
|
||
export default ProjectStatsStore; |
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
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
Oops, something went wrong.