Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
ehasa-backend
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
WIMMA Lab 2019
Overflow
ehasa-backend
Commits
ade9ca1d
Commit
ade9ca1d
authored
5 years ago
by
L4168
Browse files
Options
Downloads
Patches
Plain Diff
replay returns players, factions, scores
parent
925f13e2
No related branches found
Branches containing commit
No related tags found
3 merge requests
!59
Development to master
,
!54
Development to testing
,
!50
Mockdata replay
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/replay/replay.service.ts
+111
-40
111 additions, 40 deletions
src/replay/replay.service.ts
with
111 additions
and
40 deletions
src/replay/replay.service.ts
+
111
−
40
View file @
ade9ca1d
import
{
Injectable
}
from
'
@nestjs/common
'
;
import
{
InjectRepository
}
from
'
@nestjs/typeorm
'
;
import
{
Repository
}
from
'
typeorm
'
;
import
{
Repository
,
In
}
from
'
typeorm
'
;
import
*
as
jwt
from
'
jsonwebtoken
'
;
import
{
FactionEntity
}
from
'
../faction/faction.entity
'
;
...
...
@@ -13,6 +13,8 @@ import {
MapDrawingEntity
,
MapDrawingHistoryEntity
,
}
from
'
../draw/coordinate.entity
'
;
import
{
ScoreService
}
from
'
src/score/score.service
'
;
import
{
ScoreEntity
}
from
'
src/score/score.entity
'
;
@
Injectable
()
export
class
ReplayService
{
...
...
@@ -27,12 +29,15 @@ export class ReplayService {
private
mapdrawingRepository
:
Repository
<
MapDrawingEntity
>
,
@
InjectRepository
(
MapDrawingHistoryEntity
)
private
mapHistoryRepository
:
Repository
<
MapDrawingHistoryEntity
>
,
@
InjectRepository
(
ScoreEntity
)
private
scoreRepository
:
Repository
<
ScoreEntity
>
,
private
trackingService
:
TrackingService
,
private
userService
:
UserService
,
private
factionService
:
FactionService
,
private
scoreService
:
ScoreService
,
)
{}
async
replayData
(
gameId
)
{
/*
async replayData(gameId) {
let mapDrawingIds = await this.mapdrawingRepository.find({
where: { gameId: gameId },
select: ['mapDrawingId'],
...
...
@@ -48,10 +53,12 @@ export class ReplayService {
}),
);
return drawings;
}
}
*/
// get replay data for players
async
getPlayers
(
gameId
)
{
async
replayData
(
gameId
)
{
//
// this block returs all player data from the game
//
let
playerdata
=
await
this
.
trackingRepository
.
find
({
where
:
{
game
:
gameId
},
relations
:
[
'
faction
'
,
'
gamepersonId
'
,
'
gamepersonId.person
'
],
...
...
@@ -70,68 +77,127 @@ export class ReplayService {
return
player
[
'
data
'
];
}),
);
//
// this block return all faction data from the game
//
let
factions
=
await
this
.
factionRepository
.
find
({
game
:
gameId
});
let
currentFactions
=
factions
.
map
(
faction
=>
{
return
{
name
:
faction
.
factionName
,
colour
:
faction
.
colour
,
// all factions will be rendered on the map on default
active
:
true
,
};
});
let
factionIds
=
factions
.
map
(
faction
=>
faction
.
factionId
);
//
// this block returns all score data from the game
//
let
scores
=
await
this
.
scoreRepository
.
find
({
where
:
{
faction
:
In
(
factionIds
)
},
relations
:
[
'
faction
'
],
});
let
currentScore
=
scores
.
map
(
score
=>
{
return
{
score
:
score
.
score
,
timestamp
:
score
.
scoreTimeStamp
,
faction
:
score
.
faction
[
'
factionName
'
],
};
});
return
currentdata
;
return
{
players
:
currentdata
,
factions
:
currentFactions
,
scores
:
currentScore
,
};
}
// generate mockdata for a 3 day game
// create x amount of players
// assign them to two separate factions
// assign them to three separate groups
// insert x amount of locations for each players around some lat lng area
// insert x amount of score ticks for score mockdata
// use the game's initial geojson to draw game area
//
async
mockdata
(
gameId
)
{
// initial settings for mockdata
// set the x amount of users to be created
const
USER_AMOUNT
=
100
;
// set the x amount of locations to be created
const
USER_LOCATIONS
=
10
;
// set the LAT and LNG for initial location
const
LAT
=
62.24147
;
const
LNG
=
25.72088
;
// set the score tick amount
const
SCORE_TICKS
=
10
;
// setup the arrays for users, gamepersons and groups
const
users
=
[];
const
gamepersons
=
[];
const
groups
=
[];
// characters for generating random usernames and the length of the username
const
chars
=
'
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789
'
;
const
N
=
15
;
// used to equally divide the players to factions
let
f
=
0
;
// get game info and factions associated with it
const
game
=
await
this
.
gameRepository
.
findOne
({
where
:
{
id
:
gameId
},
relations
:
[
'
factions
'
],
});
const
groups
=
await
this
.
factionService
.
showGroups
(
game
.
factions
[
1
].
factionId
,
);
for
(
let
i
=
0
;
i
<
100
;
i
++
)
{
// get groups for all factions
await
game
.
factions
.
forEach
(
async
faction
=>
{
groups
.
push
(
await
this
.
factionService
.
showGroups
(
faction
.
factionId
));
});
// create x amount of users for the mock game with random username
for
(
let
i
=
0
;
i
<
USER_AMOUNT
;
i
++
)
{
let
res
=
await
this
.
userService
.
register
({
name
:
'
asdfasa
'
+
i
,
name
:
Array
(
N
)
.
join
()
.
split
(
'
,
'
)
.
map
(
function
()
{
return
chars
.
charAt
(
Math
.
floor
(
Math
.
random
()
*
chars
.
length
));
})
.
join
(
''
),
password
:
'
asd
'
,
});
// get user information by verifying the token returned by register
let
user
=
await
jwt
.
verify
(
res
.
token
,
process
.
env
.
SECRET
);
// push the created user to users array
users
.
push
(
user
);
/* let gameperson = await this.factionService.joinFaction(user['id'], {
factionId:
i < 10 ? game.factions[0].factionId : game.factions[1].factionId,
factionPassword:
i < 10
? game.factions[0].factionPassword
: game.factions[1].factionPassword,
game: gameId,
}); */
// reset index if it's out of range
if
(
f
===
game
.
factions
.
length
)
f
=
0
;
// join faction with the created user
let
gameperson
=
await
this
.
factionService
.
joinFaction
(
user
[
'
id
'
],
{
factionId
:
game
.
factions
[
1
].
factionId
,
factionPassword
:
game
.
factions
[
1
].
factionPassword
,
factionId
:
game
.
factions
[
f
].
factionId
,
factionPassword
:
game
.
factions
[
f
].
factionPassword
,
game
:
gameId
,
});
// join a group randomly
await
this
.
factionService
.
joinGroup
(
gameperson
,
{
groupId
:
groups
[
Math
.
floor
(
Math
.
random
()
*
3
)],
groupId
:
groups
[
f
][
Math
.
floor
(
Math
.
random
()
*
3
)],
});
// push the gameperson ref to gamepersons array
gamepersons
.
push
(
gameperson
);
f
++
;
}
let
date
:
number
=
Date
.
now
();
let
y1
=
25.7
;
let
x1
=
62.0
;
let
y2
=
25.75
;
let
x2
=
62.05
;
for
(
let
i
=
1
;
i
<
6
;
i
++
)
{
let
x
=
0
;
date
+=
10000
;
// push x amount of user locations
for
(
let
i
=
1
;
i
<
USER_LOCATIONS
+
1
;
i
++
)
{
let
date
:
number
=
Date
.
now
();
let
x
=
1
;
await
Promise
.
all
(
gamepersons
.
map
(
async
gameperson
=>
{
x
++
;
// format player locations with x-modifier that same factions are closer to each other
if
(
x
>
game
.
factions
.
length
)
x
=
1
;
let
dataObject
=
{
lat
:
x
<
50
?
x1
+
((
i
+
Math
.
random
())
*
5
)
/
2000
:
x2
-
((
i
+
Math
.
random
())
*
5
)
/
2000
,
lng
:
x
<
50
?
y1
+
((
i
+
Math
.
random
())
*
5
)
/
2000
:
y2
-
((
i
+
Math
.
random
())
*
5
)
/
2000
,
lat
:
LAT
+
((
i
+
Math
.
random
())
*
5
)
/
2000
,
lng
:
LNG
+
x
/
100
+
(
Math
.
random
()
*
5
)
/
2000
,
time
:
date
,
};
x
++
;
// push the tracking data
await
this
.
trackingService
.
trackLocation
(
gameperson
,
gameId
,
...
...
@@ -140,6 +206,11 @@ export class ReplayService {
}),
);
}
// generate x-amount of score tick
for
(
let
i
=
0
;
i
<
SCORE_TICKS
;
i
++
)
{
await
this
.
scoreService
.
scoreTick
(
gameId
);
}
return
{
message
:
'
all done
'
,
};
...
...
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