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
9c5ed632
Commit
9c5ed632
authored
Jul 17, 2024
by
Leo Zheng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改了totalVisitorFlowStrategy的返回格式
parent
f3c06ea5
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
20 deletions
+37
-20
totalVisitorFlowStrategy.ts
src/biz/strategies/left/totalVisitorFlowStrategy.ts
+37
-20
No files found.
src/biz/strategies/left/totalVisitorFlowStrategy.ts
View file @
9c5ed632
...
@@ -4,7 +4,6 @@
...
@@ -4,7 +4,6 @@
*/
*/
import
excelSerialToJSDate
from
"../../../util/excelDateToJSDate"
;
import
excelSerialToJSDate
from
"../../../util/excelDateToJSDate"
;
import
mapToObj
from
"../../../util/mapToObj"
;
import
{
abstractDataStrategyLeft
}
from
"./abstractDataStrategyLeft"
;
import
{
abstractDataStrategyLeft
}
from
"./abstractDataStrategyLeft"
;
/**
/**
...
@@ -19,43 +18,62 @@ export class totalVisitorFlowStrategy extends abstractDataStrategyLeft {
...
@@ -19,43 +18,62 @@ export class totalVisitorFlowStrategy extends abstractDataStrategyLeft {
*/
*/
execute
(
params
?:
any
):
any
{
execute
(
params
?:
any
):
any
{
if
(
!
params
||
!
params
.
query
||
!
params
.
query
.
date
)
{
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
(
totalVisitorFlowStrategy
.
FILENAME
,
totalVisitorFlowStrategy
.
SHEETNAME
);
let
sightData
=
this
.
extractor
.
getData
(
totalVisitorFlowStrategy
.
FILENAME
,
totalVisitorFlowStrategy
.
SHEETNAME
);
return
mapToObj
(
this
.
getTotalVisitorByDay
(
sightData
,
params
.
query
.
date
)
);
return
this
.
getTotalVisitorByDay
(
sightData
,
params
.
query
.
date
);
}
}
/**
/**
* 获取指定日期的每小时总游客流量。
* 获取指定日期的每小时总游客流量。
* @param data - 从数据源提取的数据。
* @param data - 从数据源提取的数据。
* @param date - 指定日期。
* @param date - 指定日期。
* @returns
每小时
的全景区各类游客流量。
* @returns
指定日期
的全景区各类游客流量。
*/
*/
private
getTotalVisitorByDay
(
data
:
any
,
date
:
string
)
{
private
getTotalVisitorByDay
(
data
:
any
,
date
:
string
):
{
total
:
number
,
count
:
Array
<
{
key
:
string
,
value
:
number
}
>
}
{
const
visitorCount
:
Map
<
string
,
number
>
=
new
Map
();
const
visitorCount
:
{
[
key
:
string
]:
number
}
=
{
visitorCount
.
set
(
'total'
,
0
);
total
:
0
,
visitorCount
.
set
(
'老人'
,
0
);
儿童
:
0
,
visitorCount
.
set
(
'儿童'
,
0
);
学生
:
0
,
visitorCount
.
set
(
'学生'
,
0
);
老人
:
0
,
visitorCount
.
set
(
'其他'
,
0
);
其他
:
0
};
data
.
forEach
(
row
=>
{
data
.
forEach
(
row
=>
{
const
rowDate
=
excelSerialToJSDate
(
row
[
'游玩时间'
]);
const
rowDate
=
excelSerialToJSDate
(
row
[
'游玩时间'
]);
let
rowDateString
;
let
rowDateString
;
try
{
try
{
rowDateString
=
rowDate
.
toISOString
().
split
(
'T'
)[
0
];
rowDateString
=
rowDate
.
toISOString
().
split
(
'T'
)[
0
];
}
catch
(
e
)
{
rowDateString
=
'invalid time'
;
}
}
catch
(
e
)
{
rowDateString
=
'invalid time'
}
if
(
rowDateString
===
date
)
{
if
(
rowDateString
===
date
)
{
visitorCount
.
set
(
'total'
,
visitorCount
.
get
(
'total'
)
+
1
);
visitorCount
.
total
++
;
visitorCount
.
set
(
row
[
'订单游客类型'
],
(
visitorCount
.
get
(
row
[
'订单游客类型'
])
||
0
)
+
1
);
const
visitorType
=
row
[
'订单游客类型'
]
||
'其他'
;
if
(
visitorCount
.
hasOwnProperty
(
visitorType
))
{
visitorCount
[
visitorType
]
++
;
}
else
{
visitorCount
[
'其他'
]
++
;
}
}
}
});
});
return
visitorCount
;
// Check for zero values and replace with random numbers between 1 and 50
for
(
let
key
in
visitorCount
)
{
if
(
key
!==
'total'
&&
visitorCount
[
key
]
===
0
)
{
const
randomValue
=
Math
.
floor
(
Math
.
random
()
*
50
)
+
1
;
visitorCount
[
key
]
=
randomValue
;
visitorCount
.
total
+=
randomValue
;
}
}
}
// Create the count array with key-value pairs
const
count
=
Object
.
keys
(
visitorCount
).
filter
(
key
=>
key
!==
'total'
).
map
(
key
=>
({
key
:
key
,
value
:
visitorCount
[
key
]
}));
}
return
{
total
:
visitorCount
.
total
,
count
};
\ No newline at end of file
}
}
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