Skip to content

Commit

Permalink
adjusted parsing of EFT and DNA fittings for changes to the game and …
Browse files Browse the repository at this point in the history
…updated display lib (eve-ui) for to necessary version
  • Loading branch information
Henjuro committed Sep 22, 2018
1 parent 640b8f3 commit 61da2c5
Show file tree
Hide file tree
Showing 18 changed files with 1,096 additions and 193 deletions.
34 changes: 34 additions & 0 deletions migrations/versions/8ec8c7bb9459_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""empty message
Revision ID: 8ec8c7bb9459
Revises: 9ab201421111
Create Date: 2018-09-10 17:52:00.595675
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '8ec8c7bb9459'
down_revision = '9ab201421111'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.create_table('dogma_effect',
sa.Column('type_id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('effect_id', sa.Integer(), autoincrement=False, nullable=False),
sa.Column('is_default', sa.Boolean(name='is_default'), nullable=True),
sa.ForeignKeyConstraint(['type_id'], ['invtypes.type_id'], name=op.f('fk_dogma_effect_type_id_invtypes'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('type_id', 'effect_id', name=op.f('pk_dogma_effect'))
)
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
op.drop_table('dogma_effect')
# ### end Alembic commands ###
83 changes: 83 additions & 0 deletions migrations/versions/9ab201421111_.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
"""empty message
Revision ID: 9ab201421111
Revises: c2b7b284ed6f
Create Date: 2018-09-08 13:40:35.106054
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '9ab201421111'
down_revision = 'c2b7b284ed6f'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###

op.drop_constraint(op.f('fk_fit_module_fit_id_fittings'), 'fit_module', type_='foreignkey')
op.drop_constraint(op.f('fk_fit_module_module_id_invtypes'), 'fit_module', type_='foreignkey')
op.drop_constraint(op.f('pk_fit_module'), 'fit_module', type_='primary')
op.add_column('fit_module', sa.Column('location_flag', sa.Integer(), nullable=False, server_default=sa.text('1000')))

# remove auto increment from invtypes table
# drop all remaining foreign keys towards the invtypes.type_id column
op.drop_constraint(op.f('fk_fittings_ship_type_invtypes'), 'fittings', type_='foreignkey')
# now we can fix the id column (remove the auto increment)
op.alter_column('invtypes', 'type_id', autoincrement=False, existing_type=sa.Integer, existing_nullable=False)
op.create_foreign_key(op.f('fk_fittings_ship_type_invtypes'), 'fittings', 'invtypes', ['ship_type'], ['type_id'], onupdate='CASCADE')
# done removing autoincrement from invtypes table

# readd keys we removed to change the primary key of fit_module
op.create_primary_key(op.f('pk_fit_module'), 'fit_module',
['fit_id', 'module_id', 'location_flag'])
op.create_foreign_key(op.f('fk_fit_module_fit_id_fittings'), 'fit_module', 'fittings', ['fit_id'], ['id'])
op.create_foreign_key(op.f('fk_fit_module_module_id_invtypes'), 'fit_module', 'invtypes', ['module_id'], ['type_id'], onupdate='CASCADE')

op.create_table('invcategory',
sa.Column('category_id', sa.Integer(), nullable=False, autoincrement=False),
sa.Column('category_name', sa.String(length=255), nullable=True),
sa.Column('published', sa.Boolean(name='is_published'), nullable=True),
sa.PrimaryKeyConstraint('category_id', name=op.f('pk_invcategory'))
)
op.create_table('dogma_attributes',
sa.Column('type_id', sa.Integer(), nullable=False, autoincrement=False),
sa.Column('attribute_id', sa.Integer(), nullable=False),
sa.Column('value', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['type_id'], ['invtypes.type_id'], name=op.f('fk_dogma_attributes_type_id_invtypes'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('type_id', 'attribute_id', name=op.f('pk_dogma_attributes'))
)
op.create_table('invgroup',
sa.Column('group_id', sa.Integer(), nullable=False, autoincrement=False),
sa.Column('group_name', sa.String(length=255), nullable=True),
sa.Column('published', sa.Boolean(name='is_published'), nullable=True),
sa.Column('category_id', sa.Integer(), nullable=True),
sa.ForeignKeyConstraint(['category_id'], ['invcategory.category_id'], name=op.f('fk_invgroup_category_id_invcategory'), ondelete='CASCADE'),
sa.PrimaryKeyConstraint('group_id', name=op.f('pk_invgroup'))
)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
# we don't need to reverse the removal of the autoincrement since it is better for older versions too
op.drop_constraint(op.f('fk_fit_module_fit_id_fittings'), 'fit_module', type_='foreignkey')
op.drop_constraint(op.f('fk_fit_module_module_id_invtypes'), 'fit_module', type_='foreignkey')
op.drop_constraint(op.f('pk_fit_module'), 'fit_module', type_='primary')

op.drop_column('fit_module', 'location_flag')

op.create_primary_key(op.f('pk_fit_module'), 'fit_module',
['fit_id', 'module_id'])
op.create_foreign_key(op.f('fk_fit_module_fit_id_fittings'), 'fit_module', 'fittings', ['fit_id'], ['id'])
op.create_foreign_key(op.f('fk_fit_module_module_id_invtypes'), 'fit_module', 'invtypes', ['module_id'], ['type_id'])

op.drop_table('invgroup')
op.drop_table('dogma_attributes')
op.drop_table('invcategory')
# ### end Alembic commands ###
21 changes: 18 additions & 3 deletions static/js/history-base.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,21 @@ waitlist.history.base = (function() {
return historyEntrySkeleton;
}

/**
* Take a string and return the same string
* unless the string is "#System"
* then return "Booby"(the bird)
* @param old_name inventory type name
* @returns old_name unless it is "#System" then it is replaced by "Booby"
*/
function filterShipName(old_name) {
if (old_name === "#System") {
return "Booby";
}
return old_name;
}


function createFittingDOM(fit) {
var comment = "";
let skillsData = "";
Expand All @@ -106,10 +121,10 @@ waitlist.history.base = (function() {
skillsData = `3338:${bsResult[1]}`;
}
}
if (fit.ship_type === 1) {
return $.parseHTML(`<a href="#" class="booby-link">${fit.shipName}${comment}</a>`);
if (fit.ship_type === 0) {
return $.parseHTML(`<a href="#" class="booby-link">${filterShipName(fit.shipName)}${comment}</a>`);
} else {
return $.parseHTML(`<a href="#" class="fit-link" data-skills="${skillsData}" data-dna="${fit.shipType+':'+fit.modules}">${fit.shipName}${comment}</a>`);
return $.parseHTML(`<a href="#" class="fit-link" data-skills="${skillsData}" data-dna="${fit.shipType+':'+fit.modules}">${filterShipName(fit.shipName)}${comment}</a>`);
}
}

Expand Down
18 changes: 16 additions & 2 deletions static/js/waitlist-dom.js
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,20 @@ waitlist.listdom = (function(){
}

}

/**
* Take a string and return the same string
* unless the string is "#System"
* then return "Booby"(the bird)
* @param old_name inventory type name
* @returns old_name unless it is "#System" then it is replaced by "Booby"
*/
function filterShipName(old_name) {
if (old_name === "#System") {
return "Booby";
}
return old_name;
}

/**
* Creat html entity of a fit
Expand All @@ -319,7 +333,7 @@ waitlist.listdom = (function(){
*/
function createFitDOM(fit, wlId, entryId, queue, username, userId) {
queue = typeof queue !== 'undefined' ? queue : false;
var isDummy = fit.shipType === 1;
var isDummy = fit.shipType === 0;
var approveButton = "", fitButtons = "",commentHTML = "";
// if user can manage fleet and if on x'ups
if (settings.can_manage && queue) {
Expand Down Expand Up @@ -347,7 +361,7 @@ waitlist.listdom = (function(){
commentHTML = `<div id="fit-${wlId}-${entryId}-${fit.id}-comment"><small>${fit.comment}</small></div>`;
}
// text html with ship name and comment
var textHTML = '<div class="wel-text-row-32-2">'+fit.shipName+commentHTML+'</div>';
var textHTML = '<div class="wel-text-row-32-2">'+filterShipName(fit.shipName)+commentHTML+'</div>';

var fitDOM = $('<li class="list-group-item" id="fit-'+wlId+"-"+entryId+"-"+fit.id+'" data-type="'+getTagFromJsonFit(fit)+'" role="button"></li>');

Expand Down
4 changes: 2 additions & 2 deletions templates/libs/eve-ui.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% assets filters="babili", output="gen/eve-ui.%(version)s.js", "js/eve-ui-config.js" %}
<script type="text/javascript" src="{{ ASSET_URL }}" defer async></script>
{% endassets %}
<script src="https://cdn.jsdelivr.net/gh/quiescens/[email protected].5/eve-ui.min.js"
integrity="sha384-YT+7P/Z8j9L3NhTHOEvpdsTYLh/SkqtFRyW5hQ8LMSsIf8AAHrCKZAZjVdW5r0jX"
<script src="https://cdn.jsdelivr.net/gh/quiescens/[email protected].7/eve-ui.min.js"
integrity="sha384-CYdXNHiwMBnRCTgugs/I+XgCxorz56Z9/XTIZ5Qwf5r3Tc3XBsACY9YyitJP0Z1u"
crossorigin="anonymous" async defer></script>
96 changes: 57 additions & 39 deletions waitlist/blueprints/xup/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@

from waitlist.blueprints.api.fittings.self import self_remove_fit
from waitlist.data.names import WaitlistNames
from waitlist.data.sse import EntryAddedSSE, send_server_sent_event, FitAddedSSE
from waitlist.storage.database import WaitlistGroup, WaitlistEntry, Shipfit, InvType, FitModule,\
MarketGroup, HistoryEntry
from waitlist.storage.modules import resist_ships, logi_ships, sniper_ships, sniper_weapons, dps_weapons, weapongroups,\
dps_ships, t3c_ships
from waitlist.utility.database_utils import parse_eft
from waitlist.data.sse import EntryAddedSSE, send_server_sent_event,\
FitAddedSSE
from waitlist.storage.database import WaitlistGroup, WaitlistEntry, Shipfit,\
InvType, FitModule, MarketGroup, HistoryEntry
from waitlist.storage.modules import resist_ships, logi_ships, sniper_ships,\
sniper_weapons, dps_weapons, weapongroups, dps_ships, t3c_ships
from waitlist.utility.history_utils import create_history_object
from waitlist.utility.utils import get_fit_format, create_mod_map
from waitlist.utility.fitting_utils import get_fit_format, parse_dna_fitting,\
parse_eft
from waitlist import db
from . import bp
from flask_babel import gettext, ngettext
from typing import Dict, List, Tuple
from waitlist.utility.constants import location_flags

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -89,7 +92,7 @@ def submit():

for stype in ship_types:
fit = Shipfit()
fit.ship_type = 1 # #System >.>
fit.ship_type = 0 # #System >.>
fit.wl_type = stype
fit.modules = ':'
wl_entry.fittings.append(fit)
Expand Down Expand Up @@ -172,24 +175,29 @@ def submit():
# parse chat links
lines = fittings.split('\n')
for line in lines:
fit_iter = re.finditer("<url=fitting:(\d+):((?:\d+;\d+:)+:)>", line)
fit_iter = re.finditer(
"<url=fitting:(\d+):((?:\d+_{0,1};\d+:)+:)>",
line)
for fitMatch in fit_iter:
ship_type = int(fitMatch.group(1))
dna_fit = fitMatch.group(2)
fit = Shipfit()
fit.ship_type = ship_type
fit.modules = dna_fit
mod_map = create_mod_map(dna_fit)
for modid in mod_map:
mod = mod_map[modid]

# lets check the value actually exists
inv_type = db.session.query(InvType).get(mod[0])
if inv_type is None:
raise ValueError('No module with ID=' + str(mod[0]))

db_module = FitModule(moduleID=mod[0], amount=mod[1])
fit.moduleslist.append(db_module)
mod_list = parse_dna_fitting(dna_fit)
for location_flag, mod_map in enumerate(mod_list):
for mod_id in mod_map:
mod = mod_map[mod_id]

# lets check the value actually exists
inv_type = db.session.query(InvType).get(mod[0])
if inv_type is None:
raise ValueError(
'No module with ID=' + str(mod[0]))

db_module = FitModule(moduleID=mod[0], amount=mod[1],
locationFlag=location_flag)
fit.moduleslist.append(db_module)
fits.append(fit)

fit_count = len(fits)
Expand Down Expand Up @@ -242,9 +250,9 @@ def submit():

# split his fits into types for the different waitlist_entries
for fit in fits:
mod_map = dict()
mod_list: List[Dict[int, Tuple(int, int)]]
try:
mod_map = create_mod_map(fit.modules)
mod_list = parse_dna_fitting(fit.modules)
except ValueError:
abort(400, "Invalid module amounts")
# check that ship is an allowed ship
Expand All @@ -265,33 +273,50 @@ def submit():
continue

# filter out mods that don't exist at least 4 times
# this way we avoid checking everything or choosing the wrong weapon on ships that have 7turrents + 1launcher
# this way we avoid checking everything or choosing the wrong weapon
# on ships that have 7turrents + 1launcher
possible_weapons = []
for mod in mod_map:
if mod_map[mod][1] >= 4:
high_slot_mod_map = mod_list[location_flags.HIGH_SLOT]
for mod in high_slot_mod_map:
if high_slot_mod_map[mod][1] >= 4:
possible_weapons.append(mod)
else:
# precursor weapons only use 1 turret
inv_type: InvType = db.session.query(InvType).get(mod)
if inv_type is None:
continue
if inv_type.group.groupName == 'Precursor Weapon':
possible_weapons.append(mod)

weapon_type = "None"
for weapon in possible_weapons:
inv_type: InvType = db.session.query(InvType).get(mod)
if inv_type.group.groupName == 'Precursor Weapon':
weapon_type = WaitlistNames.dps
break
if weapon in sniper_weapons:
weapon_type = WaitlistNames.sniper
break
if weapon in dps_weapons:
weapon_type = WaitlistNames.dps
break
if inv_type.group.groupName in ['Remote Shield Booster',
'Remote Armor Repairer']:
weapon_type = WaitlistNames.logi
break

if weapon_type == "None":
# try to decide by market group
for weapon in possible_weapons:
weapon_db = db.session.query(InvType).filter(InvType.typeID == weapon).first()
weapon_db = db.session.query(InvType).get(weapon)
if weapon_db is None:
continue
market_group = db.session.query(MarketGroup).filter(
MarketGroup.marketGroupID == weapon_db.marketGroupID).first()
market_group = db.session.query(MarketGroup).get(
weapon_db.marketGroupID)
if market_group is None:
continue
parent_group = db.session.query(MarketGroup).filter(
MarketGroup.marketGroupID == market_group.parentGroupID).first()
parent_group = db.session.query(MarketGroup).get(
market_group.parentGroupID)
if parent_group is None:
continue

Expand All @@ -308,15 +333,8 @@ def submit():
fit.wl_type = WaitlistNames.other
fits_ready.append(fit)
continue

# ships with sniper weapons put on sniper wl
if weapon_type == WaitlistNames.sniper:
fit.wl_type = WaitlistNames.sniper
fits_ready.append(fit)
continue

if weapon_type == WaitlistNames.dps:
fit.wl_type = WaitlistNames.dps
else:
fit.wl_type = weapon_type
fits_ready.append(fit)
continue

Expand Down
Loading

0 comments on commit 61da2c5

Please sign in to comment.