-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCSVgenerateRatings.py
62 lines (53 loc) · 1.99 KB
/
CSVgenerateRatings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Dec 30 18:55:19 2020
@author: Lotte&Major
"""
import csv
from faker import Faker
import datetime
from games_provider import GamesProvider
from random import randrange
def primaryKeygenerator(list_of_used_game_user_touples):
while True:
gameid = randrange(10)
userid = randrange(10)
if gameid in list_of_used_game_user_touples :
list_of_used_user_touples = list_of_used_game_user_touples[gameid]
if userid in list_of_used_user_touples :
print("bewertung gibts schon, neu random")
else :
list_of_used_user_touples[userid] = "true"
list_of_used_game_user_touples[gameid] = list_of_used_user_touples
break
else:
list_of_used_game_user_touples[gameid] = { userid : "true" }
break
return gameid, userid, list_of_used_game_user_touples
def datagenerate(records, headers):
fake = Faker('en_US')
fake.add_provider(GamesProvider)
with open("ratings_data.csv", 'wt') as csvFile:
writer = csv.DictWriter(csvFile, fieldnames=headers)
writer.writeheader()
# erstelle Müllbeutel = leer
list_of_used_game_user_touples = {}
for i in range(records):
graphic_value = randrange(5) + 1
sound_value = randrange(5) + 1
addict_value = randrange(5) + 1
gameid, userid, list_of_used_game_user_touples = primaryKeygenerator( list_of_used_game_user_touples )
writer.writerow({
"Graphic" : graphic_value,
"Sound" : sound_value,
"AddictiveScore": addict_value,
"OptionalComment": fake.sentence(),
"UserId": userid,
"GameId": gameid
})
if __name__ == '__main__':
records = 10
headers = ["Graphic","Sound","AddictiveScore","OptionalComment","UserId", "GameId"]
datagenerate(records, headers)
print("CSV generation complete!")