@@ -16,6 +16,12 @@ <h1>WebXR Input Profile Asset Stats</h1>
16
16
broader trends in device usage on the web.
17
17
</ p >
18
18
19
+ < form id ='args ' method ='GET '>
20
+ < label for ='period '> Period:</ label >
21
+ < input name ='period ' type ='text ' placeholder ='YYYY-MM ' />
22
+ < input type ='submit ' value ='Refresh '/>
23
+ </ form >
24
+
19
25
< h2 > Profile List requests</ h2 >
20
26
< p >
21
27
Almost all uses of the library fetch this list prior to requesting specific assets, so it serves as a rough
@@ -39,14 +45,26 @@ <h2>Profile requests</h2>
39
45
< canvas id ='profilesPieChart '> </ canvas >
40
46
41
47
< script >
42
- const JSDELIVR_API_ROOT = 'https://data.jsdelivr.com/v1/package/ npm/@webxr -input-profiles/assets' ; //@1.0.0/stats';
48
+ const JSDELIVR_API_ROOT = 'https://data.jsdelivr.com/v1/stats/packages/ npm/%40webxr -input-profiles%2Fassets'
43
49
44
50
const profileListCtx = document . getElementById ( 'profileListChart' ) . getContext ( '2d' ) ;
45
51
const profilesCtx = document . getElementById ( 'profilesChart' ) . getContext ( '2d' ) ;
46
52
const profilesPieCtx = document . getElementById ( 'profilesPieChart' ) . getContext ( '2d' ) ;
47
53
48
- async function processVersions ( ) {
49
- let response = await fetch ( JSDELIVR_API_ROOT ) ;
54
+ let profileListChart ;
55
+ let profilesChart ;
56
+ let profilesPieChart ;
57
+
58
+ const argsForm = document . getElementById ( 'args' ) ;
59
+ argsForm . addEventListener ( 'submit' , ( ev ) => {
60
+ ev . preventDefault ( ) ;
61
+ const args = new FormData ( argsForm ) ;
62
+ processVersions ( args ) ;
63
+ } ) ;
64
+
65
+ async function processVersions ( args = new FormData ( ) ) {
66
+ let queryArgs = new URLSearchParams ( args ) . toString ( ) ;
67
+ let response = await fetch ( `${ JSDELIVR_API_ROOT } /versions?${ queryArgs } ` ) ;
50
68
let versionJson = await response . json ( ) ;
51
69
52
70
let stats = {
@@ -57,8 +75,8 @@ <h2>Profile requests</h2>
57
75
} ;
58
76
59
77
let statPromises = [ ] ;
60
- for ( let version of versionJson . versions ) {
61
- statPromises . push ( processVersionStats ( version , stats ) ) ;
78
+ for ( let version of versionJson ) {
79
+ statPromises . push ( processVersionStats ( version . version , stats , args ) ) ;
62
80
}
63
81
await Promise . all ( statPromises ) ;
64
82
@@ -73,30 +91,24 @@ <h2>Profile requests</h2>
73
91
processStats ( stats ) ;
74
92
}
75
93
76
- async function processVersionStats ( version , stats ) {
77
- let response = await fetch ( `${ JSDELIVR_API_ROOT } @${ version } /stats` ) ;
94
+ async function processVersionStats ( version , stats , args ) {
95
+ let queryArgs = new URLSearchParams ( args ) . toString ( ) ;
96
+ let response = await fetch ( `${ JSDELIVR_API_ROOT } @${ version } /files?${ queryArgs } ` ) ;
78
97
let statsJson = await response . json ( ) ;
79
98
80
- let profileListStats = statsJson . files [ '/dist/profiles/profilesList.json' ] ;
81
-
82
- if ( ! profileListStats ) {
83
- return ;
84
- }
85
-
86
- for ( let date in profileListStats . dates ) {
87
- if ( ! stats . profileList . dates [ date ] ) {
88
- stats . profileList . dates [ date ] = 0 ;
89
- }
90
- stats . profileList . dates [ date ] += profileListStats . dates [ date ] ;
91
- }
92
-
93
- for ( let key in statsJson . files ) {
94
- if ( / .j s o n $ / . test ( key ) && key != '/dist/profiles/profilesList.json' ) {
95
- let profile = statsJson . files [ key ] ;
96
- let total = profile . total ;
99
+ for ( let file of statsJson ) {
100
+ if ( file . name === '/dist/profiles/profilesList.json' ) {
101
+ for ( let date in file . hits . dates ) {
102
+ if ( ! stats . profileList . dates [ date ] ) {
103
+ stats . profileList . dates [ date ] = 0 ;
104
+ }
105
+ stats . profileList . dates [ date ] += file . hits . dates [ date ] ;
106
+ }
107
+ } else if ( / .j s o n $ / . test ( file . name ) && file . name != '/dist/profiles/profilesList.json' ) {
108
+ let total = file . hits . total ;
97
109
if ( total == 0 ) continue ;
98
110
99
- let label = key . replace ( '/dist/profiles/' , '' ) . replace ( '/profile.json' , '' ) ;
111
+ let label = file . name . replace ( '/dist/profiles/' , '' ) . replace ( '/profile.json' , '' ) ;
100
112
if ( ! stats . profiles [ label ] ) {
101
113
stats . profiles [ label ] = {
102
114
total : 0 ,
@@ -105,11 +117,11 @@ <h2>Profile requests</h2>
105
117
}
106
118
stats . profiles [ label ] . total += total ;
107
119
108
- for ( let date in profile . dates ) {
120
+ for ( let date in file . hits . dates ) {
109
121
if ( ! stats . profiles [ label ] . dates [ date ] ) {
110
122
stats . profiles [ label ] . dates [ date ] = 0 ;
111
123
}
112
- stats . profiles [ label ] . dates [ date ] += profile . dates [ date ] ;
124
+ stats . profiles [ label ] . dates [ date ] += file . hits . dates [ date ] ;
113
125
}
114
126
}
115
127
}
@@ -118,7 +130,8 @@ <h2>Profile requests</h2>
118
130
function processStats ( stats ) {
119
131
let dateLabels = Object . keys ( stats . profileList . dates ) ;
120
132
121
- let profileListChart = new Chart ( profileListCtx , {
133
+ if ( profileListChart ) { profileListChart . destroy ( ) ; }
134
+ profileListChart = new Chart ( profileListCtx , {
122
135
type : 'line' ,
123
136
data : {
124
137
labels : dateLabels ,
@@ -188,15 +201,17 @@ <h2>Profile requests</h2>
188
201
} ) ;
189
202
}
190
203
191
- let profilesChart = new Chart ( profilesCtx , {
204
+ if ( profilesChart ) { profilesChart . destroy ( ) ; }
205
+ profilesChart = new Chart ( profilesCtx , {
192
206
type : 'line' ,
193
207
data : {
194
208
labels : dateLabels ,
195
209
datasets : profileDatasets
196
210
} ,
197
211
} ) ;
198
212
199
- let profilesPieChart = new Chart ( profilesPieCtx , {
213
+ if ( profilesPieChart ) { profilesPieChart . destroy ( ) ; }
214
+ profilesPieChart = new Chart ( profilesPieCtx , {
200
215
type : 'doughnut' ,
201
216
data : {
202
217
labels : profileLabels ,
0 commit comments