Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
V
VIPSWeb
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
VIPS
VIPSWeb
Commits
69522820
Commit
69522820
authored
1 year ago
by
Tor-Einar Skog
Browse files
Options
Downloads
Patches
Plain Diff
Add trimming of weather data object
parent
5256bdae
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ipmd/static/ipmd/js/ipmdlib.js
+56
-0
56 additions, 0 deletions
ipmd/static/ipmd/js/ipmdlib.js
with
56 additions
and
0 deletions
ipmd/static/ipmd/js/ipmdlib.js
+
56
−
0
View file @
69522820
...
...
@@ -531,9 +531,65 @@ function mergeWeatherData(primaryData, secondaryData)
}
mergedData
.
locationWeatherData
[
0
].
data
=
dataSet
;
trimWeatherData
(
mergedData
);
return
mergedData
;
}
/**
* Removes NULL rows at the beginning and end of a dataset
* Assumes only one locationWeatherData
* @param {Object} weatherData
*/
function
trimWeatherData
(
weatherData
)
{
// Find index of first and last non-NULL rows
let
firstIndex
=
0
;
outer_loop_first
:
for
(
let
i
=
0
;
i
<
weatherData
.
locationWeatherData
[
0
].
data
.
length
;
i
++
)
{
let
row
=
weatherData
.
locationWeatherData
[
0
].
data
[
i
];
if
(
row
!=
undefined
&&
row
!=
null
)
{
for
(
let
j
=
0
;
j
<
row
.
length
;
j
++
)
{
if
(
row
[
j
]
!=
undefined
&&
row
[
j
]
!=
null
)
{
firstIndex
=
i
;
break
outer_loop_first
;
}
}
}
}
let
lastIndex
=
weatherData
.
locationWeatherData
[
0
].
data
.
length
-
1
;
outer_loop_last
:
for
(
let
i
=
lastIndex
;
i
>=
0
;
i
--
)
{
let
row
=
weatherData
.
locationWeatherData
[
0
].
data
[
i
];
if
(
row
!=
undefined
&&
row
!=
null
)
{
for
(
let
j
=
0
;
j
<
row
.
length
;
j
++
)
{
if
(
row
[
j
]
!=
undefined
&&
row
[
j
]
!=
null
)
{
lastIndex
=
i
;
break
outer_loop_last
;
}
}
}
}
// Adjust timeStart and timeEnd based on indexes
let
adjustedTimeStart
=
moment
(
weatherData
.
timeStart
).
add
(
firstIndex
,
(
weatherData
.
interval
==
86400
?
'
days
'
:
'
hours
'
));
let
adjustedTimeEnd
=
moment
(
weatherData
.
timeEnd
).
subtract
(
weatherData
.
locationWeatherData
[
0
].
data
.
length
-
1
-
lastIndex
,
(
weatherData
.
interval
==
86400
?
'
days
'
:
'
hours
'
));
weatherData
.
timeStart
=
adjustedTimeStart
;
weatherData
.
timeEnd
=
adjustedTimeEnd
;
weatherData
.
locationWeatherData
[
0
].
data
=
weatherData
.
locationWeatherData
[
0
].
data
.
slice
(
firstIndex
,
lastIndex
+
1
);
}
/**
* Util method if you don't know the type of object you're trying to get a Unix timestamp from
* @param {Object} aDate
...
...
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