working on the loader.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,9 +2,11 @@
|
|||||||
node_modules
|
node_modules
|
||||||
frontent/dist
|
frontent/dist
|
||||||
backend/dist
|
backend/dist
|
||||||
|
loader/venv
|
||||||
# sqlite file
|
# sqlite file
|
||||||
*.db
|
*.db
|
||||||
*.sqbpro
|
*.sqbpro
|
||||||
|
*.csv
|
||||||
|
|
||||||
# local env files
|
# local env files
|
||||||
.env.local
|
.env.local
|
||||||
|
|||||||
@@ -47,11 +47,11 @@
|
|||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</v-table>
|
</v-table>
|
||||||
<div class="chart d-flex flex-column">
|
<v-sheet class="chart d-flex flex-column">
|
||||||
|
<v-select v-model="chartSelect" :items="chartItems"></v-select>
|
||||||
|
<canvas id="piechart"></canvas>
|
||||||
<div class="flex-1-1"></div>
|
<div class="flex-1-1"></div>
|
||||||
<canvas id="piechart" class="chart"></canvas>
|
</v-sheet>
|
||||||
<div class="flex-1-1"></div>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -79,8 +79,9 @@
|
|||||||
margin-right: 15px;
|
margin-right: 15px;
|
||||||
}
|
}
|
||||||
.chart {
|
.chart {
|
||||||
|
margin-left: 20px;
|
||||||
width: 25%;
|
width: 25%;
|
||||||
min-width: 500px;
|
width: 450px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
@@ -93,6 +94,14 @@ const dateSelect = ref(-1)
|
|||||||
|
|
||||||
const dateItems = buildDateItems()
|
const dateItems = buildDateItems()
|
||||||
|
|
||||||
|
const chartSelect = ref("active")
|
||||||
|
|
||||||
|
const chartItems = [
|
||||||
|
{title: "Active Characters", value: "active"},
|
||||||
|
{title: "Role Picks", value: "picks"},
|
||||||
|
{title: "Role Applications", value: "apps"}
|
||||||
|
]
|
||||||
|
|
||||||
const gameStats = ref({})
|
const gameStats = ref({})
|
||||||
|
|
||||||
const roleStats = ref({})
|
const roleStats = ref({})
|
||||||
@@ -136,21 +145,30 @@ function dateToMonthId(date: Date) {
|
|||||||
return (date.getUTCFullYear() - 2023) * 12 + date.getUTCMonth()
|
return (date.getUTCFullYear() - 2023) * 12 + date.getUTCMonth()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function updateChart(stats, tag) {
|
||||||
|
chart.data = {
|
||||||
|
labels: Object.keys(stats),
|
||||||
|
datasets: [
|
||||||
|
{
|
||||||
|
label: tag,
|
||||||
|
data: Object.values(stats).map((p) => p[tag])
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
chart.update()
|
||||||
|
}
|
||||||
|
|
||||||
watch(dateSelect, async (newValue, oldValue) => {
|
watch(dateSelect, async (newValue, oldValue) => {
|
||||||
loadData()
|
loadData()
|
||||||
})
|
})
|
||||||
|
|
||||||
watch(roleStats, async (newValue, oldValue) => {
|
watch(roleStats, async (newValue, oldValue) => {
|
||||||
chart.data = {
|
updateChart(newValue, chartSelect.value)
|
||||||
labels: Object.keys(roleStats.value),
|
})
|
||||||
datasets: [
|
|
||||||
{
|
watch(chartSelect, async (newValue, oldValue) => {
|
||||||
label: 'Active',
|
|
||||||
data: Object.values(roleStats.value).map((p) => p.active)
|
updateChart(roleStats.value, newValue)
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
chart.update()
|
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
|
|||||||
113
loader/databasesync.py
Normal file
113
loader/databasesync.py
Normal file
@@ -0,0 +1,113 @@
|
|||||||
|
import csv
|
||||||
|
import sqlite3
|
||||||
|
from datetime import datetime
|
||||||
|
from collections import namedtuple
|
||||||
|
|
||||||
|
|
||||||
|
Character = namedtuple('Character',
|
||||||
|
['id', 'characterName', 'playerName', 'role', 'creationDate', 'status'])
|
||||||
|
|
||||||
|
Game = namedtuple('Game',
|
||||||
|
['id', 'title', 'status', 'fix', 'event', 'postdate', 'gamemaster', 'payouteb', 'payoutip', 'payoutloot'])
|
||||||
|
|
||||||
|
Link = namedtuple('Link', ['gameId', 'gameTitle', 'characterId', 'characterName'])
|
||||||
|
|
||||||
|
def extractCharacterFromRow(counter, row):
|
||||||
|
return Character(
|
||||||
|
counter,
|
||||||
|
row['Character'],
|
||||||
|
row['Player'],
|
||||||
|
row['Role'],
|
||||||
|
int(datetime.strptime(row['Approval Date'],'%m/%d/%Y').timestamp()) if row['Approval Date'] else 0,
|
||||||
|
row['Status'])
|
||||||
|
|
||||||
|
def extractGameFromRow(counter, row):
|
||||||
|
return Game(
|
||||||
|
counter,
|
||||||
|
row['Game Title'],
|
||||||
|
row['Game Status'],
|
||||||
|
row['Fix'],
|
||||||
|
0,
|
||||||
|
int(datetime.strptime(row['Game Date'],'%d-%b-%Y').timestamp()) if row['Game Date'] else 0,
|
||||||
|
row['GM'],
|
||||||
|
row['Payout (EB)'],
|
||||||
|
row['Payout (IP)'],
|
||||||
|
row['Payout (Loot)'])
|
||||||
|
|
||||||
|
def loadCharacters(characterFileName):
|
||||||
|
characters = []
|
||||||
|
characterNameToId = {}
|
||||||
|
|
||||||
|
with open(characterFileName) as csvFile:
|
||||||
|
reader = csv.DictReader(csvFile)
|
||||||
|
counter = 1
|
||||||
|
for row in reader:
|
||||||
|
character = extractCharacterFromRow(counter, row)
|
||||||
|
if character.characterName:
|
||||||
|
characters.append(character)
|
||||||
|
characterNameToId[character.characterName] = counter
|
||||||
|
counter += 1
|
||||||
|
|
||||||
|
return characters, characterNameToId
|
||||||
|
|
||||||
|
def loadGames(gameFileName):
|
||||||
|
games = []
|
||||||
|
gameTitleToId = {}
|
||||||
|
|
||||||
|
with open(gameFileName) as csvFile:
|
||||||
|
reader = csv.DictReader(csvFile)
|
||||||
|
counter = 1
|
||||||
|
for row in reader:
|
||||||
|
game = extractGameFromRow(counter, row)
|
||||||
|
if game.title:
|
||||||
|
games.append(game)
|
||||||
|
gameTitleToId[game.title] = counter
|
||||||
|
counter += 1
|
||||||
|
|
||||||
|
return games, gameTitleToId
|
||||||
|
|
||||||
|
def loadAppsAndPicks(characterNameToId, gameTitleToId, gameFileName):
|
||||||
|
apps = []
|
||||||
|
picks = []
|
||||||
|
|
||||||
|
with open(gameFileName) as csvFile:
|
||||||
|
reader = csv.DictReader(csvFile)
|
||||||
|
for row in reader:
|
||||||
|
gameTitle = row['Game Title']
|
||||||
|
if (gameTitle):
|
||||||
|
gameId = gameTitleToId[gameTitle]
|
||||||
|
for i in range(1,7):
|
||||||
|
characterName = row['Character {} (Player)'.format(i)]
|
||||||
|
if characterName:
|
||||||
|
characterId = characterNameToId[characterName]
|
||||||
|
picks.append(Link(gameId, gameTitle, characterId, characterName))
|
||||||
|
for i in range(7,11):
|
||||||
|
characterName = row['Character {}'.format(i)]
|
||||||
|
if (characterName):
|
||||||
|
characterId = characterNameToId[characterName]
|
||||||
|
picks.append(Link(gameId, gameTitle, characterId, characterName))
|
||||||
|
for i in range(1,51):
|
||||||
|
characterName = row['Applicant {}'.format(i)]
|
||||||
|
if characterName:
|
||||||
|
characterId = characterNameToId[characterName]
|
||||||
|
apps.append(Link(gameId, gameTitle, characterId, characterName))
|
||||||
|
|
||||||
|
return apps, picks
|
||||||
|
|
||||||
|
def main():
|
||||||
|
characters, characterNameToId = loadCharacters("Character Data.csv")
|
||||||
|
games, gameTitleToId = loadGames("Game Data.csv")
|
||||||
|
apps, picks = loadAppsAndPicks(characterNameToId, gameTitleToId, "Game Data.csv")
|
||||||
|
|
||||||
|
with sqlite3.connect('testdb.db') as connection:
|
||||||
|
cursor = connection.cursor()
|
||||||
|
for character in characters:
|
||||||
|
cursor.execute("""
|
||||||
|
REPLACE INTO Characters (characterName, id, playerName, role, creationDate, status)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?)
|
||||||
|
""", [character.characterName, character.id, character.playerName, character.role, character.creationDate, character.status])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
0
loader/sheetloader.py
Normal file
0
loader/sheetloader.py
Normal file
Reference in New Issue
Block a user