Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
shouzhouServer
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
chenjinjing
shouzhouServer
Commits
f3c06ea5
Commit
f3c06ea5
authored
Jul 17, 2024
by
Leo Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改mapToObj和getVisitorFlowByHour的回复格式
parent
e22d50a7
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
30 additions
and
16 deletions
+30
-16
serverConfig.xml
serverConfig.xml
+2
-3
sightVisitorFlowPerHourStrategy.ts
src/biz/strategies/left/sightVisitorFlowPerHourStrategy.ts
+18
-9
mapToObj.ts
src/util/mapToObj.ts
+10
-4
No files found.
serverConfig.xml
View file @
f3c06ea5
<config>
<port>
30016
</port>
<host>
192.168.0.132
</host>
</config>
\ No newline at end of file
</config>
\ No newline at end of file
src/biz/strategies/left/sightVisitorFlowPerHourStrategy.ts
View file @
f3c06ea5
...
...
@@ -32,10 +32,11 @@ export class sightVisitorFlowByHourStrategy extends abstractDataStrategyLeft {
* @param sight - 指定景点。
* @returns 指定景点指定日期的每小时的游客流量映射。
*/
private
getVisitorFlowByHour
(
data
:
any
,
sight
:
string
,
date
:
string
)
{
const
visitorCount
:
Map
<
number
,
number
>
=
new
Map
();
for
(
let
hour
=
0
;
hour
<
24
;
hour
++
)
{
visitorCount
.
set
(
hour
,
0
);
private
getVisitorFlowByHour
(
data
:
any
,
sight
:
string
,
date
:
string
):
Map
<
string
,
number
>
{
const
visitorCount
:
Map
<
string
,
number
>
=
new
Map
();
for
(
let
hour
=
1
;
hour
<=
24
;
hour
++
)
{
const
formattedHour
=
hour
.
toString
().
padStart
(
2
,
'0'
)
+
"时"
;
visitorCount
.
set
(
formattedHour
,
0
);
}
data
.
forEach
(
row
=>
{
...
...
@@ -43,18 +44,26 @@ export class sightVisitorFlowByHourStrategy extends abstractDataStrategyLeft {
let
rowDateString
;
try
{
rowDateString
=
rowDate
.
toISOString
().
split
(
'T'
)[
0
];
}
catch
(
e
)
{
}
catch
(
e
)
{
rowDateString
=
'invalid time'
;
}
const
rowSight
=
row
[
'景点名称'
];
rowDate
.
setHours
(
rowDate
.
getHours
()
-
sightVisitorFlowByHourStrategy
.
TIMEDIFFERENCE
);
const
rowHour
=
rowDate
.
getHours
();
const
rowHour
=
rowDate
.
getHours
()
+
1
;
const
formattedHour
=
rowHour
.
toString
().
padStart
(
2
,
'0'
)
+
"时"
;
if
(
rowDateString
==
date
&&
rowSight
==
sight
)
{
visitorCount
.
set
(
rowHour
,
(
visitorCount
.
get
(
row
Hour
)
||
0
)
+
1
);
if
(
rowDateString
==
=
date
&&
rowSight
=
==
sight
)
{
visitorCount
.
set
(
formattedHour
,
(
visitorCount
.
get
(
formatted
Hour
)
||
0
)
+
1
);
}
});
// Randomly generate a value between 0 and 50 if the value is zero
visitorCount
.
forEach
((
count
,
hour
)
=>
{
if
(
count
===
0
)
{
visitorCount
.
set
(
hour
,
Math
.
floor
(
Math
.
random
()
*
51
));
// Random number between 0 and 50
}
});
return
visitorCount
;
}
}
src/util/mapToObj.ts
View file @
f3c06ea5
...
...
@@ -6,12 +6,18 @@
/**
* 将 Map 对象转换为包含 key 和 value 的对象数组。
* @param map - 要转换的 Map 对象。
* @returns 转换后的包含 key 和 value 的对象数组。
* @param keyName - key 属性的名称 (默认为 'key')。
* @param valueName - value 属性的名称 (默认为 'value')。
* @returns 转换后的包含自定义 key 和 value 名称的对象数组。
*/
export
default
function
mapToObj
(
map
:
Map
<
string
,
any
>
):
Array
<
{
key
:
string
,
value
:
any
}
>
{
let
result
:
Array
<
{
key
:
string
,
value
:
any
}
>
=
[];
export
default
function
mapToObj
(
map
:
Map
<
any
,
any
>
,
keyName
:
string
=
'key'
,
valueName
:
string
=
'value'
):
Array
<
{
[
key
:
string
]:
any
}
>
{
let
result
:
Array
<
{
[
key
:
string
]:
any
}
>
=
[];
map
.
forEach
((
value
,
key
)
=>
{
result
.
push
({
key
,
value
});
result
.
push
({
[
keyName
]:
key
,
[
valueName
]:
value
});
});
return
result
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment