Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
onTime
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
onTime InnoLab
onTime
Commits
4c7f421e
Commit
4c7f421e
authored
1 year ago
by
doodlezucc
Browse files
Options
Downloads
Patches
Plain Diff
move fetch statistics to separate class
parent
68df2013
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/untis/fetch.dart
+42
-21
42 additions, 21 deletions
lib/untis/fetch.dart
with
42 additions
and
21 deletions
lib/untis/fetch.dart
+
42
−
21
View file @
4c7f421e
...
...
@@ -11,7 +11,7 @@ import 'element_type.dart';
import
'lecture.dart'
;
typedef
RequestOptions
=
(
String
path
,
String
method
,
Json
params
);
typedef
JsonWithCookies
=
(
Json
json
,
List
<
Cookie
>
cookies
);
typedef
RequestResult
=
(
Json
json
,
List
<
Cookie
>
cookies
,
FetchStats
stats
);
class
UntisFetch
{
static
const
String
apiBase
=
'/WebUntis/api/public'
;
...
...
@@ -64,10 +64,10 @@ class UntisFetch {
return
response
;
}
Future
<
JsonWithCookies
>
_requestJson
(
RequestOptions
options
)
async
{
Future
<
RequestResult
>
_requestJson
(
RequestOptions
options
)
async
{
final
(
_
,
String
method
,
_
)
=
options
;
final
before
=
DateTime
.
now
();
final
onStart
=
DateTime
.
now
();
final
response
=
await
_request
(
method
,
_makeUri
(
options
));
final
cookies
=
response
.
cookies
;
...
...
@@ -79,30 +79,19 @@ class UntisFetch {
}
}
final
afterDownloadStart
=
DateTime
.
now
();
final
responseTime
=
afterDownloadStart
.
difference
(
before
);
final
onDownloadStart
=
DateTime
.
now
();
final
responseString
=
await
utf8
.
decodeStream
(
response
);
final
afterDownloadEnd
=
DateTime
.
now
();
final
downloadTime
=
afterDownloadEnd
.
difference
(
afterDownloadStart
);
final
onDownloadEnd
=
DateTime
.
now
();
final
bodyJson
=
jsonDecode
(
responseString
);
final
afterDecode
=
DateTime
.
now
();
final
decodeTime
=
afterDecode
.
difference
(
afterDownloadEnd
);
final
onDecodeEnd
=
DateTime
.
now
();
final
timeStats
=
{
'Ping'
:
responseTime
,
'Download'
:
downloadTime
,
'JSON'
:
decodeTime
,
};
final
stats
=
FetchStats
(
onStart
,
onDownloadStart
,
onDownloadEnd
,
onDecodeEnd
);
print
(
timeStats
.
entries
.
map
((
e
)
=
>
'
${e.key}
:
${e.value.inMilliseconds}
ms'
)
.
join
(
', '
));
return
(
bodyJson
as
Json
,
resultCookies
);
return
(
bodyJson
as
Json
,
resultCookies
,
stats
);
}
Future
<
Json
>
requestOptions
(
RequestOptions
options
)
async
{
...
...
@@ -112,9 +101,10 @@ class UntisFetch {
final
methodPadded
=
method
.
padRight
(
8
);
print
(
'
$methodPadded
$uri
'
);
final
(
result
,
cookies
)
=
await
compute
(
_requestJson
,
options
);
final
(
result
,
cookies
,
stats
)
=
await
compute
(
_requestJson
,
options
);
_sessionCookies
.
addAll
(
cookies
);
print
(
'
$stats
'
);
return
result
;
}
...
...
@@ -127,3 +117,34 @@ class UntisFetch {
return
await
requestOptions
(
options
);
}
}
class
FetchStats
{
final
DateTime
onStart
;
final
DateTime
onDownloadStart
;
final
DateTime
onDownloadEnd
;
final
DateTime
onDecodeEnd
;
FetchStats
(
this
.
onStart
,
this
.
onDownloadStart
,
this
.
onDownloadEnd
,
this
.
onDecodeEnd
,
);
@override
String
toString
()
{
final
responseTime
=
onDownloadStart
.
difference
(
onStart
);
final
downloadTime
=
onDownloadEnd
.
difference
(
onDownloadStart
);
final
decodeTime
=
onDecodeEnd
.
difference
(
onDownloadEnd
);
final
timeStats
=
{
'Ping'
:
responseTime
,
'Download'
:
downloadTime
,
'JSON'
:
decodeTime
,
};
return
timeStats
.
entries
.
map
((
e
)
=
>
'
${e.key}
:
${e.value.inMilliseconds}
ms'
)
.
join
(
', '
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment