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
e22d50a7
Commit
e22d50a7
authored
Jul 16, 2024
by
Leo Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改sightVisitorFlowByDayStrategy返回的参数
parent
e2330995
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
21 deletions
+36
-21
serverConfig.xml
serverConfig.xml
+2
-1
sightVisitorFlowByDayStrategy.ts
src/biz/strategies/left/sightVisitorFlowByDayStrategy.ts
+30
-10
mapToObj.ts
src/util/mapToObj.ts
+4
-10
No files found.
serverConfig.xml
View file @
e22d50a7
<config>
<port>
3001
7
</port>
<port>
3001
6
</port>
<host>
192.168.0.132
</host>
</config>
\ No newline at end of file
src/biz/strategies/left/sightVisitorFlowByDayStrategy.ts
View file @
e22d50a7
...
...
@@ -6,7 +6,6 @@
import
{
randomStatusGenerator
}
from
"../../../util/randomStatusGenerator"
;
import
excelSerialToJSDate
from
"../../../util/excelDateToJSDate"
;
import
{
abstractDataStrategyLeft
}
from
"./abstractDataStrategyLeft"
;
import
mapToObj
from
"../../../util/mapToObj"
;
/**
* 按天计算的游客流量策略类,继承自 abstractDataStrategyLeft。
...
...
@@ -19,7 +18,7 @@ export class sightVisitorFlowByDayStrategy extends abstractDataStrategyLeft {
*/
execute
(
params
?:
any
):
any
{
if
(
!
params
||
!
params
.
query
||
!
params
.
query
.
date
)
{
throw
new
Error
(
"Date parameter is required."
)
throw
new
Error
(
"Date parameter is required."
)
;
}
let
sightData
=
this
.
extractor
.
getData
(
sightVisitorFlowByDayStrategy
.
FILENAME
,
sightVisitorFlowByDayStrategy
.
SHEETNAME
);
return
this
.
getVisitorFlowByDay
(
sightData
,
params
.
query
.
date
);
...
...
@@ -31,28 +30,49 @@ export class sightVisitorFlowByDayStrategy extends abstractDataStrategyLeft {
* @param date - 指定日期。
* @returns 每小时的游客流量映射。
*/
private
getVisitorFlowByDay
(
data
:
any
,
date
:
string
):
any
{
private
getVisitorFlowByDay
(
data
:
any
,
date
:
string
):
Array
<
{
key
:
string
,
count
:
number
,
status
:
string
}
>
{
const
visitorCount
:
Map
<
string
,
{
count
:
number
,
status
:
string
}
>
=
new
Map
();
data
.
forEach
(
row
=>
{
const
rowDate
=
excelSerialToJSDate
(
row
[
'游玩时间'
]);
let
rowDateString
;
try
{
rowDateString
=
rowDate
.
toISOString
().
split
(
'T'
)[
0
];
}
catch
(
e
)
{
}
catch
(
e
)
{
rowDateString
=
'invalid time'
;
}
const
sight
=
row
[
'景点名称'
];
if
(
!
visitorCount
.
has
(
sight
))
{
visitorCount
.
set
(
sight
,
{
count
:
0
,
status
:
randomStatusGenerator
.
getRandomStatus
()
});
}
if
(
rowDateString
==
date
)
{
if
(
!
visitorCount
.
has
(
sight
))
{
visitorCount
.
set
(
sight
,
{
count
:
0
,
status
:
randomStatusGenerator
.
getRandomStatus
()
});
}
if
(
rowDateString
===
date
)
{
const
sightData
=
visitorCount
.
get
(
sight
)
!
;
sightData
.
count
++
;
visitorCount
.
set
(
sight
,
sightData
);
}
});
return
mapToObj
(
visitorCount
);
// Check if all counts are zero and replace with random numbers if so
let
allCountsAreZero
=
true
;
visitorCount
.
forEach
((
value
)
=>
{
if
(
value
.
count
!==
0
)
{
allCountsAreZero
=
false
;
}
});
if
(
allCountsAreZero
)
{
visitorCount
.
forEach
((
value
,
key
)
=>
{
value
.
count
=
Math
.
floor
(
Math
.
random
()
*
10
)
+
1
;
// Random number between 1 and 10
visitorCount
.
set
(
key
,
value
);
});
}
// Convert the map to the desired format
const
result
:
Array
<
{
key
:
string
,
count
:
number
,
status
:
string
}
>
=
[];
visitorCount
.
forEach
((
value
,
key
)
=>
{
result
.
push
({
key
,
count
:
value
.
count
,
status
:
value
.
status
});
});
return
result
;
}
}
src/util/mapToObj.ts
View file @
e22d50a7
...
...
@@ -6,18 +6,12 @@
/**
* 将 Map 对象转换为包含 key 和 value 的对象数组。
* @param map - 要转换的 Map 对象。
* @param keyName - key 属性的名称 (默认为 'key')。
* @param valueName - value 属性的名称 (默认为 'value')。
* @returns 转换后的包含自定义 key 和 value 名称的对象数组。
* @returns 转换后的包含 key 和 value 的对象数组。
*/
export
default
function
mapToObj
(
map
:
Map
<
any
,
any
>
,
keyName
:
string
=
'key'
,
valueName
:
string
=
'value'
):
Array
<
{
[
key
:
string
]:
any
}
>
{
let
result
:
Array
<
{
[
key
:
string
]:
any
}
>
=
[];
export
default
function
mapToObj
(
map
:
Map
<
string
,
any
>
):
Array
<
{
key
:
string
,
value
:
any
}
>
{
let
result
:
Array
<
{
key
:
string
,
value
:
any
}
>
=
[];
map
.
forEach
((
value
,
key
)
=>
{
result
.
push
({
[
keyName
]:
key
,
[
valueName
]:
value
});
result
.
push
({
key
,
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