529 lines
15 KiB
Python
529 lines
15 KiB
Python
import uuid
|
|
from pymongo import MongoClient
|
|
from faker import Faker
|
|
import json
|
|
import datetime
|
|
import random
|
|
from pymongo import ReturnDocument
|
|
from enum import Enum
|
|
|
|
|
|
class QuestContentState(Enum):
|
|
NoneState = 0
|
|
Editable = 1
|
|
Test = 2
|
|
Standby = 3
|
|
Live = 4
|
|
Shutdown = 5
|
|
|
|
class CreatorPointHistoryKind(Enum):
|
|
NoneKind = 0
|
|
QuestProfit = 1
|
|
AvatarReceived = 2
|
|
CashReceived = 3
|
|
|
|
def random_datetime():
|
|
year = random.randrange(2019,2025)
|
|
month = random.randrange(1,13)
|
|
day = random.randrange(1,28)
|
|
hour = random.randrange(0,24)
|
|
minute = random.randrange(0, 60)
|
|
second = random.randrange(0, 60)
|
|
return datetime.datetime(year, month, day, hour, minute, second)
|
|
|
|
|
|
def drop_all():
|
|
account_collection = ugq_db.get_collection("Account")
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
like_collection = ugq_db.get_collection("Like")
|
|
bookmark_collection = ugq_db.get_collection("Bookmark")
|
|
cp_history_collection = ugq_db.get_collection("CreatorPointHistory")
|
|
|
|
quest_accepted_collection = ugq_db.get_collection("QuestAccepted")
|
|
quest_aborted_collection = ugq_db.get_collection("QuestAborted")
|
|
quest_completed_collection = ugq_db.get_collection("QuestCompleted")
|
|
report_collection = ugq_db.get_collection("Report")
|
|
|
|
account_collection.drop()
|
|
quest_content_collection.drop()
|
|
like_collection.drop()
|
|
bookmark_collection.drop()
|
|
cp_history_collection.drop()
|
|
quest_accepted_collection.drop()
|
|
quest_aborted_collection.drop()
|
|
quest_completed_collection.drop()
|
|
report_collection.drop()
|
|
|
|
pass
|
|
|
|
def init():
|
|
quest_sequence = ugq_db.get_collection("QuestIdSequence")
|
|
|
|
filter = {"_id": "QuestId" }
|
|
|
|
found_doc = quest_sequence.find_one(filter)
|
|
if found_doc is None:
|
|
doc = {
|
|
"_id": "QuestId",
|
|
"Sequence": 0,
|
|
"CreatedAt": datetime.datetime.now(),
|
|
"UpdatedAt": datetime.datetime.now(),
|
|
}
|
|
|
|
ret = quest_sequence.insert_one(doc)
|
|
print("QuestIdSequence: " + str(ret))
|
|
|
|
|
|
|
|
def get_next_quest_id(ugq_db):
|
|
|
|
quest_sequence = ugq_db.get_collection("QuestIdSequence")
|
|
|
|
filter = {"_id": "QuestId" }
|
|
update = {
|
|
'$inc': {'Sequence' : 1},
|
|
'$set': {'UpdatedAt': datetime.datetime.now() }
|
|
}
|
|
|
|
updated_doc = quest_sequence.find_one_and_update(
|
|
filter, update,
|
|
return_document=ReturnDocument.AFTER
|
|
)
|
|
|
|
return updated_doc["Sequence"]
|
|
|
|
|
|
def insert_fake_account(ugq_db, count):
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
# account_collection.drop()
|
|
|
|
fake_kr = Faker('ko_KR')
|
|
for i in range(count):
|
|
created_at = random_datetime()
|
|
|
|
cp = random.randrange(1, 5000)
|
|
|
|
account_doc = {
|
|
"UserGuid": str(uuid.uuid4()),
|
|
"Nickname": fake_kr.name(),
|
|
"AdditionalSlotCount": 0,
|
|
"GradeType": "Amature",
|
|
"CreatorPoint": cp,
|
|
"CreatedAt": created_at,
|
|
"UpdatedAt": created_at,
|
|
}
|
|
|
|
ret = account_collection.insert_one(account_doc)
|
|
print("Account: " + str(ret))
|
|
|
|
pass
|
|
|
|
|
|
def insert_fake_quest_tasks(ugq_db, quest_content_id):
|
|
pass
|
|
|
|
|
|
def insert_fake_quest_content(ugq_db):
|
|
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
# quest_content_collection.drop()
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
accounts = []
|
|
cursor = account_collection.find({})
|
|
for document in cursor:
|
|
accounts.append({
|
|
"UserGuid": document["UserGuid"],
|
|
"Nickname": document["Nickname"]
|
|
})
|
|
|
|
fake_en = Faker('en_US')
|
|
fake_kr = Faker('ko_KR')
|
|
fake_jp = Faker('ja_JP')
|
|
for account in accounts:
|
|
|
|
create_count = random.randrange(1, 3)
|
|
for i in range(create_count):
|
|
|
|
created_at = random_datetime()
|
|
|
|
quest_id = get_next_quest_id(ugq_db)
|
|
revision = random.randrange(1, 1000)
|
|
cost = random.randrange(100, 5000)
|
|
|
|
beacon_id = random.randrange(1001, 1059)
|
|
|
|
randValue = random.randrange(0, len(QuestContentState))
|
|
state = QuestContentState(randValue).name
|
|
if randValue == 0:
|
|
state = "None"
|
|
|
|
quest_content_doc = {
|
|
"UserGuid": account["UserGuid"],
|
|
"Author": account["Nickname"],
|
|
"GradeType": "Amature",
|
|
"QuestId": quest_id,
|
|
"Revision": revision,
|
|
"BeaconId": beacon_id,
|
|
"Title": {
|
|
"Kr": fake_kr.company(),
|
|
"En": fake_en.company(),
|
|
"Jp": fake_jp.company(),
|
|
},
|
|
"Langs": ["en", "kr", "jp"],
|
|
"UploadCounter": 0,
|
|
"TitleImagePath": "",
|
|
"BannerImagePath": "",
|
|
"Description": {
|
|
"Kr": fake_kr.catch_phrase(),
|
|
"En": fake_en.catch_phrase(),
|
|
"Jp": fake_jp.catch_phrase(),
|
|
},
|
|
"State": "Live",
|
|
"Cost": cost,
|
|
"Tasks": [],
|
|
"CreatedAt": created_at,
|
|
"UpdatedAt": created_at,
|
|
"IsDeleted": False,
|
|
"DeletedAt": datetime.datetime(1, 1, 1)
|
|
}
|
|
|
|
# print(quest_content_doc)
|
|
ret = quest_content_collection.insert_one(quest_content_doc)
|
|
print("QuestContent: " + str(ret))
|
|
# for account in accounts:
|
|
|
|
|
|
def insert_fake_like(ugq_db):
|
|
|
|
like_collection = ugq_db.get_collection("Like")
|
|
# like_collection.drop()
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
user_guids = []
|
|
cursor = account_collection.find({})
|
|
for document in cursor:
|
|
user_guids.append(document["UserGuid"])
|
|
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
quest_ids = []
|
|
cursor = quest_content_collection.find({})
|
|
for document in cursor:
|
|
quest_ids.append(document["QuestId"])
|
|
|
|
for user_guid in user_guids:
|
|
|
|
quest_ids_copy = quest_ids.copy()
|
|
random.shuffle(quest_ids_copy)
|
|
|
|
count = random.randrange(1, len(quest_ids_copy))
|
|
|
|
for i in range(count):
|
|
|
|
created_at = random_datetime()
|
|
|
|
like_doc = {
|
|
"QuestId": quest_ids_copy[i],
|
|
"UserGuid": user_guid,
|
|
"CreatedAt": created_at,
|
|
}
|
|
|
|
ret = like_collection.insert_one(like_doc)
|
|
print("Like: " + str(ret))
|
|
# for i in range(count):
|
|
|
|
# for user_guid in user_guids:
|
|
|
|
|
|
def insert_fake_bookmark(ugq_db):
|
|
|
|
bookmark_collection = ugq_db.get_collection("Bookmark")
|
|
# bookmark_collection.drop()
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
user_guids = []
|
|
cursor = account_collection.find({})
|
|
for document in cursor:
|
|
user_guids.append(document["UserGuid"])
|
|
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
quest_ids = []
|
|
cursor = quest_content_collection.find({})
|
|
for document in cursor:
|
|
quest_ids.append(document["QuestId"])
|
|
|
|
for user_guid in user_guids:
|
|
|
|
quest_ids_copy = quest_ids.copy()
|
|
random.shuffle(quest_ids_copy)
|
|
|
|
count = random.randrange(1, len(quest_ids_copy))
|
|
|
|
for i in range(count):
|
|
|
|
created_at = random_datetime()
|
|
|
|
bookmark_doc = {
|
|
"QuestId": quest_ids_copy[i],
|
|
"UserGuid": user_guid,
|
|
"CreatedAt": created_at,
|
|
}
|
|
|
|
ret = bookmark_collection.insert_one(bookmark_doc)
|
|
print("Bookmark: " + str(ret))
|
|
# for i in range(count):
|
|
|
|
# for user_guid in user_guids:
|
|
|
|
|
|
def insert_fake_creator_point_history(ugq_db):
|
|
|
|
cp_history_collection = ugq_db.get_collection("CreatorPointHistory")
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
user_guids = []
|
|
cursor = account_collection.find({})
|
|
for document in cursor:
|
|
user_guids.append(document["UserGuid"])
|
|
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
quest_ids = []
|
|
cursor = quest_content_collection.find({})
|
|
for document in cursor:
|
|
quest_ids.append({
|
|
"questId": document["QuestId"],
|
|
"revision": document["Revision"],
|
|
})
|
|
|
|
for user_guid in user_guids:
|
|
count = random.randrange(1, 100)
|
|
|
|
for i in range(count):
|
|
created_at = random_datetime()
|
|
|
|
randValue = random.randrange(1, len(CreatorPointHistoryKind))
|
|
kind = CreatorPointHistoryKind(randValue).name
|
|
|
|
amount = 0
|
|
if kind == "QuestProfit":
|
|
amount = random.randrange(1, 5000)
|
|
else:
|
|
amount = -random.randrange(1, 5000)
|
|
|
|
randValue = random.randrange(0, len(quest_ids) - 1)
|
|
questId = quest_ids[randValue]["questId"]
|
|
revision = quest_ids[randValue]["revision"]
|
|
|
|
cp_history_doc = {
|
|
"UserGuid": user_guid,
|
|
"QuestId": questId,
|
|
"Revision": revision,
|
|
"Kind": kind,
|
|
"DetailReason": "",
|
|
"Amount": amount,
|
|
"TotalAmount": amount,
|
|
"CreatedAt": created_at
|
|
}
|
|
|
|
ret = cp_history_collection.insert_one(cp_history_doc)
|
|
print("CreatorPointHistory: " + str(ret))
|
|
# for i in range(count):
|
|
# for user_guid in user_guids:
|
|
pass
|
|
|
|
def insert_fake_quest_accepted(ugq_db):
|
|
|
|
quest_accepted_collection = ugq_db.get_collection("QuestAccepted")
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
user_guids = []
|
|
cursor = account_collection.find({})
|
|
for document in cursor:
|
|
user_guids.append(document["UserGuid"])
|
|
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
quest_ids = []
|
|
cursor = quest_content_collection.find({})
|
|
for document in cursor:
|
|
quest_ids.append({
|
|
"questId": document["QuestId"],
|
|
"revision": document["Revision"],
|
|
})
|
|
|
|
for user_guid in user_guids:
|
|
count = random.randrange(1, 100)
|
|
|
|
for i in range(count):
|
|
created_at = random_datetime()
|
|
|
|
randValue = random.randrange(0, len(quest_ids) - 1)
|
|
questId = quest_ids[randValue]["questId"]
|
|
revision = quest_ids[randValue]["revision"]
|
|
|
|
accepted_doc = {
|
|
"QuestId": questId,
|
|
"Revision": revision,
|
|
"UserGuid": user_guid,
|
|
"Reason": "Player",
|
|
"CreatedAt": created_at
|
|
}
|
|
|
|
ret = quest_accepted_collection.insert_one(accepted_doc)
|
|
print("QuestAccepted: " + str(ret))
|
|
# for i in range(count):
|
|
# for user_guid in user_guids:
|
|
pass
|
|
|
|
def insert_fake_quest_aborted(ugq_db):
|
|
|
|
quest_aborted_collection = ugq_db.get_collection("QuestAborted")
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
user_guids = []
|
|
cursor = account_collection.find({})
|
|
for document in cursor:
|
|
user_guids.append(document["UserGuid"])
|
|
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
quest_ids = []
|
|
cursor = quest_content_collection.find({})
|
|
for document in cursor:
|
|
quest_ids.append({
|
|
"questId": document["QuestId"],
|
|
"revision": document["Revision"],
|
|
})
|
|
|
|
for user_guid in user_guids:
|
|
count = random.randrange(1, 100)
|
|
|
|
for i in range(count):
|
|
created_at = random_datetime()
|
|
|
|
randValue = random.randrange(0, len(quest_ids) - 1)
|
|
questId = quest_ids[randValue]["questId"]
|
|
revision = quest_ids[randValue]["revision"]
|
|
|
|
aborted_doc = {
|
|
"QuestId": questId,
|
|
"Revision": revision,
|
|
"UserGuid": user_guid,
|
|
"Reason": "Player",
|
|
"CreatedAt": created_at
|
|
}
|
|
|
|
ret = quest_aborted_collection.insert_one(aborted_doc)
|
|
print("QuestAborted: " + str(ret))
|
|
# for i in range(count):
|
|
# for user_guid in user_guids:
|
|
pass
|
|
|
|
def insert_fake_quest_completed(ugq_db):
|
|
|
|
quest_completed_collection = ugq_db.get_collection("QuestCompleted")
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
user_guids = []
|
|
cursor = account_collection.find({})
|
|
for document in cursor:
|
|
user_guids.append(document["UserGuid"])
|
|
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
quest_ids = []
|
|
cursor = quest_content_collection.find({})
|
|
for document in cursor:
|
|
quest_ids.append({
|
|
"questId": document["QuestId"],
|
|
"revision": document["Revision"],
|
|
})
|
|
|
|
for user_guid in user_guids:
|
|
count = random.randrange(1, 100)
|
|
|
|
for i in range(count):
|
|
created_at = random_datetime()
|
|
|
|
randValue = random.randrange(0, len(quest_ids) - 1)
|
|
questId = quest_ids[randValue]["questId"]
|
|
revision = quest_ids[randValue]["revision"]
|
|
|
|
completed_doc = {
|
|
"QuestId": questId,
|
|
"Revision": revision,
|
|
"UserGuid": user_guid,
|
|
"CreatedAt": created_at
|
|
}
|
|
|
|
ret = quest_completed_collection.insert_one(completed_doc)
|
|
print("QuestCompleted: " + str(ret))
|
|
# for i in range(count):
|
|
# for user_guid in user_guids:
|
|
pass
|
|
|
|
def insert_fake_report(ugq_db):
|
|
|
|
report_collection = ugq_db.get_collection("Report")
|
|
|
|
account_collection = ugq_db.get_collection("Account")
|
|
user_guids = []
|
|
cursor = account_collection.find({})
|
|
for document in cursor:
|
|
user_guids.append(document["UserGuid"])
|
|
|
|
quest_content_collection = ugq_db.get_collection("QuestContent")
|
|
quest_ids = []
|
|
cursor = quest_content_collection.find({})
|
|
for document in cursor:
|
|
quest_ids.append({
|
|
"questId": document["QuestId"],
|
|
"revision": document["Revision"],
|
|
})
|
|
|
|
for user_guid in user_guids:
|
|
count = random.randrange(1, 100)
|
|
|
|
for i in range(count):
|
|
created_at = random_datetime()
|
|
|
|
randValue = random.randrange(0, len(quest_ids) - 1)
|
|
questId = quest_ids[randValue]["questId"]
|
|
revision = quest_ids[randValue]["revision"]
|
|
|
|
report_doc = {
|
|
"QuestId": questId,
|
|
"Revision": revision,
|
|
"UserGuid": user_guid,
|
|
"Content": "신고고고곡",
|
|
"CreatedAt": created_at
|
|
}
|
|
|
|
ret = report_collection.insert_one(report_doc)
|
|
print("Report: " + str(ret))
|
|
# for i in range(count):
|
|
# for user_guid in user_guids:
|
|
pass
|
|
|
|
if __name__ == '__main__':
|
|
|
|
conn_string = "mongodb://root:root@127.0.0.1:27017"
|
|
|
|
client = MongoClient(conn_string)
|
|
|
|
ugq_db = client['UGQ']
|
|
|
|
drop_all()
|
|
init()
|
|
|
|
insert_fake_account(ugq_db, 100)
|
|
insert_fake_quest_content(ugq_db)
|
|
|
|
insert_fake_like(ugq_db)
|
|
insert_fake_bookmark(ugq_db)
|
|
|
|
insert_fake_creator_point_history(ugq_db)
|
|
insert_fake_quest_accepted(ugq_db)
|
|
insert_fake_quest_aborted(ugq_db)
|
|
insert_fake_quest_completed(ugq_db)
|
|
insert_fake_report(ugq_db)
|
|
|