|
1 | 1 | import mongoose from 'mongoose'; |
2 | | -import adoptionService from './adoption.service.js'; |
| 2 | +import adoptionService, { AdoptionType } from './adoption.service.js'; |
3 | 3 | import app from 'index.js'; |
| 4 | +import { SettingsType } from './settings.service.js'; |
4 | 5 |
|
5 | 6 | interface Target { |
6 | 7 | current: number; |
@@ -53,75 +54,66 @@ class TargetValuesService { |
53 | 54 | } |
54 | 55 | } |
55 | 56 |
|
| 57 | + calculateTargets(settings: SettingsType, adoptions: AdoptionType[]): Targets { |
| 58 | + |
| 59 | + console.log('tmp', settings); |
| 60 | + |
| 61 | + const topAdoptions = adoptions |
| 62 | + .sort((a, b) => b.totalActive - a.totalActive) |
| 63 | + .slice(0, 10); |
| 64 | + |
| 65 | + const averages = topAdoptions.reduce((acc, curr) => { |
| 66 | + return { |
| 67 | + totalSeats: acc.totalSeats + curr.totalSeats, |
| 68 | + totalActive: acc.totalActive + curr.totalActive, |
| 69 | + totalInactive: acc.totalInactive + curr.totalInactive |
| 70 | + }; |
| 71 | + }, { totalSeats: 0, totalActive: 0, totalInactive: 0 }); |
| 72 | + |
| 73 | + const avgTotalSeats = Math.round(averages.totalSeats / topAdoptions.length); |
| 74 | + const avgTotalActive = Math.round(averages.totalActive / topAdoptions.length); |
| 75 | + |
| 76 | + return { |
| 77 | + org: { |
| 78 | + seats: { current: avgTotalSeats, target: avgTotalSeats, max: avgTotalSeats }, |
| 79 | + adoptedDevs: { current: avgTotalActive, target: avgTotalActive, max: avgTotalSeats }, |
| 80 | + monthlyDevsReportingTimeSavings: { current: 0, target: 0, max: avgTotalSeats }, |
| 81 | + percentOfSeatsReportingTimeSavings: { current: 0, target: 0, max: 100 }, |
| 82 | + percentOfSeatsAdopted: { |
| 83 | + current: Math.round((avgTotalActive / avgTotalSeats) * 100), |
| 84 | + target: Math.round((avgTotalActive / avgTotalSeats) * 100), |
| 85 | + max: 100 |
| 86 | + }, |
| 87 | + percentOfMaxAdopted: { current: 0, target: 0, max: 100 }, |
| 88 | + }, |
| 89 | + user: { |
| 90 | + dailySuggestions: { current: 0, target: 0, max: 0 }, |
| 91 | + dailyAcceptances: { current: 0, target: 0, max: 0 }, |
| 92 | + dailyChatTurns: { current: 0, target: 0, max: 0 }, |
| 93 | + dailyDotComChats: { current: 0, target: 0, max: 0 }, |
| 94 | + weeklyPRSummaries: { current: 0, target: 0, max: 0 }, |
| 95 | + weeklyTimeSavedHrs: { current: 0, target: 0, max: 0 }, |
| 96 | + }, |
| 97 | + impact: { |
| 98 | + monthlyTimeSavingsHrs: { current: 0, target: 0, max: 0 }, |
| 99 | + annualTimeSavingsAsDollars: { current: 0, target: 0, max: 0 }, |
| 100 | + productivityOrThroughputBoostPercent: { current: 0, target: 0, max: 100 }, |
| 101 | + }, |
| 102 | + }; |
| 103 | + } |
| 104 | + |
56 | 105 | async initialize() { |
57 | 106 | try { |
58 | 107 | const Targets = mongoose.model('Targets'); |
59 | 108 | const existingTargets = await Targets.findOne(); |
60 | 109 |
|
61 | | - if (!existingTargets) { |
62 | | - const { |
63 | | - devCostPerYear = 100000, |
64 | | - percentCoding, |
65 | | - percentTimeSaved, |
66 | | - developerCount, |
67 | | - hoursPerYear |
68 | | - } = await app.settingsService.getAllSettings(); |
69 | | - |
70 | | - console.log('tmp', { |
71 | | - devCostPerYear, |
72 | | - percentCoding, |
73 | | - percentTimeSaved, |
74 | | - developerCount, |
75 | | - hoursPerYear |
76 | | - }); |
77 | | - |
| 110 | + if (1 || !existingTargets) { |
| 111 | + const settings = await app.settingsService.getAllSettings(); |
78 | 112 | const adoptions = await adoptionService.getAllAdoptions2({ |
79 | 113 | filter: { enterprise: 'enterprise' }, |
80 | 114 | projection: {} |
81 | 115 | }); |
82 | | - |
83 | | - const topAdoptions = adoptions |
84 | | - .sort((a, b) => b.totalActive - a.totalActive) |
85 | | - .slice(0, 10); |
86 | | - |
87 | | - const averages = topAdoptions.reduce((acc, curr) => { |
88 | | - return { |
89 | | - totalSeats: acc.totalSeats + curr.totalSeats, |
90 | | - totalActive: acc.totalActive + curr.totalActive, |
91 | | - totalInactive: acc.totalInactive + curr.totalInactive |
92 | | - }; |
93 | | - }, { totalSeats: 0, totalActive: 0, totalInactive: 0 }); |
94 | | - |
95 | | - const avgTotalSeats = Math.round(averages.totalSeats / topAdoptions.length); |
96 | | - const avgTotalActive = Math.round(averages.totalActive / topAdoptions.length); |
97 | | - |
98 | | - const initialData: Targets = { |
99 | | - org: { |
100 | | - seats: { current: avgTotalSeats, target: avgTotalSeats, max: avgTotalSeats }, |
101 | | - adoptedDevs: { current: avgTotalActive, target: avgTotalActive, max: avgTotalSeats }, |
102 | | - monthlyDevsReportingTimeSavings: { current: 0, target: 0, max: avgTotalSeats }, |
103 | | - percentOfSeatsReportingTimeSavings: { current: 0, target: 0, max: 100 }, |
104 | | - percentOfSeatsAdopted: { |
105 | | - current: Math.round((avgTotalActive / avgTotalSeats) * 100), |
106 | | - target: Math.round((avgTotalActive / avgTotalSeats) * 100), |
107 | | - max: 100 |
108 | | - }, |
109 | | - percentOfMaxAdopted: { current: 0, target: 0, max: 100 }, |
110 | | - }, |
111 | | - user: { |
112 | | - dailySuggestions: { current: 0, target: 0, max: 0 }, |
113 | | - dailyAcceptances: { current: 0, target: 0, max: 0 }, |
114 | | - dailyChatTurns: { current: 0, target: 0, max: 0 }, |
115 | | - dailyDotComChats: { current: 0, target: 0, max: 0 }, |
116 | | - weeklyPRSummaries: { current: 0, target: 0, max: 0 }, |
117 | | - weeklyTimeSavedHrs: { current: 0, target: 0, max: 0 }, |
118 | | - }, |
119 | | - impact: { |
120 | | - monthlyTimeSavingsHrs: { current: 0, target: 0, max: 0 }, |
121 | | - annualTimeSavingsAsDollars: { current: 0, target: 0, max: 0 }, |
122 | | - productivityOrThroughputBoostPercent: { current: 0, target: 0, max: 100 }, |
123 | | - }, |
124 | | - }; |
| 116 | + const initialData = this.calculateTargets(settings, adoptions); |
125 | 117 | await Targets.create(initialData); |
126 | 118 | } |
127 | 119 | } catch (error) { |
|
0 commit comments