-
Notifications
You must be signed in to change notification settings - Fork 28
/
import_masteries.py
executable file
·164 lines (134 loc) · 6.42 KB
/
import_masteries.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#!/usr/bin/env python
# ------------------------------------------------------------------------------
# Copyright (c) 2010-2013, EVEthing team
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
# ------------------------------------------------------------------------------
import os
import sys
import time
# Set up our environment and import settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'evething.settings'
from django.db import connections
from thing.models.skill import Skill
from thing.models.skillplan import SkillPlan
from thing.models.spentry import SPEntry
from thing.models.spskill import SPSkill
from thing.helpers import roman
def time_func(text, f):
start = time.time()
print '=> %s:' % text,
sys.stdout.flush()
added = f()
print '%d (%0.2fs)' % (added, time.time() - start)
class Importer:
def __init__(self):
self.cursor = connections['import'].cursor()
# sqlite3 UTF drama workaround
connections['import'].connection.text_factory = lambda x: unicode(x, "utf-8", "ignore")
def import_all(self):
time_func('Masteries', self.import_masteries)
# -----------------------------------------------------------------------
def import_masteries(self):
# Masteries
added = 0
# Delete existing mastery skillplans
SkillPlan.objects.filter(visibility=SkillPlan.MASTERY_VISIBILITY).delete()
self.cursor.execute("""
SELECT s.skillID, s.skillLevel, m.masteryLevel, t.typeID, t.typeName
FROM certSkills AS s
JOIN certMasteries AS m ON s.certId = m.certID AND s.certLevelInt = m.masteryLevel
JOIN invTypes AS t on m.typeId = t.typeID
""")
ship_masteries = {}
for row in self.cursor:
if row[1] > 0:
if row[3] not in ship_masteries:
ship_masteries[row[3]] = {
'typeID': row[3],
'name': row[4],
'masteries': {}
}
if row[2] not in ship_masteries[row[3]]['masteries']:
ship_masteries[row[3]]['masteries'][row[2]] = {}
if row[0] in ship_masteries[row[3]]['masteries'][row[2]]:
if row[1] > ship_masteries[row[3]]['masteries'][row[2]][row[0]]:
ship_masteries[row[3]]['masteries'][row[2]][row[0]] = row[1]
else:
ship_masteries[row[3]]['masteries'][row[2]][row[0]] = row[1]
for type_id in ship_masteries:
entries = []
for mastery_level in ship_masteries[type_id]['masteries']:
print('==> Created Plan: %s - Mastery %s' % (ship_masteries[type_id]['name'], roman(mastery_level + 1)))
skillplan = SkillPlan.objects.create(
name='%s - Mastery %s' % (ship_masteries[type_id]['name'], roman(mastery_level + 1)),
visibility=SkillPlan.MASTERY_VISIBILITY
)
seen = {}
position = 0
for skill_id in ship_masteries[type_id]['masteries'][mastery_level]:
level = ship_masteries[type_id]['masteries'][mastery_level][skill_id]
# Get prereqs
prereqs = Skill.get_prereqs(skill_id)
for pre_skill_id, pre_level in prereqs:
for i in range(seen.get(pre_skill_id, 0) + 1, pre_level + 1):
# print('\t%d:\t%d' % (pre_skill_id, i))
try:
sps = SPSkill.objects.create(
skill_id=pre_skill_id,
level=i,
priority=3,
)
except:
continue
entries.append(SPEntry(
skill_plan=skillplan,
position=position,
sp_skill=sps,
))
position += 1
seen[pre_skill_id] = i
# Add the actual skill
for i in range(seen.get(skill_id, 0) + 1, level + 1):
# print('\t%d:\t%d' % (skill_id, i))
try:
sps = SPSkill.objects.create(
skill_id=skill_id,
level=i,
priority=3,
)
except:
continue
entries.append(SPEntry(
skill_plan=skillplan,
position=position,
sp_skill=sps,
))
position += 1
seen[skill_id] = i
added += 1
SPEntry.objects.bulk_create(entries)
return added
# ---------------------------------------------------------------------------
if __name__ == '__main__':
importer = Importer()
importer.import_all()