forked from madcowfred/evething
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodels.py
More file actions
705 lines (556 loc) · 24.6 KB
/
Copy pathmodels.py
File metadata and controls
705 lines (556 loc) · 24.6 KB
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
from django.contrib.auth.models import User
from django.db import models
from django.db.models import Q, Avg, Sum
from mptt.models import MPTTModel, TreeForeignKey
import datetime
import math
import time
from decimal import *
# ---------------------------------------------------------------------------
# API keys
class APIKey(models.Model):
ACCOUNT_TYPE = 'Account'
CHARACTER_TYPE = 'Character'
CORPORATION_TYPE = 'Corporation'
user = models.ForeignKey(User)
id = models.IntegerField(primary_key=True, verbose_name='Key ID')
vcode = models.CharField(max_length=64, verbose_name='Verification code')
name = models.CharField(max_length=64)
access_mask = models.BigIntegerField(null=True, blank=True)
key_type = models.CharField(max_length=16, null=True, blank=True)
expires = models.DateTimeField(null=True, blank=True)
valid = models.BooleanField(default=True)
# this is only used for corporate keys, ugh
corp_character = models.ForeignKey('Character', null=True, blank=True, related_name='corporate_apikey')
paid_until = models.DateTimeField(null=True, blank=True)
class Meta:
ordering = ('id',)
def __unicode__(self):
return '#%s (%s)' % (self.id, self.key_type)
def get_masked_vcode(self):
return '%s%s%s' % (self.vcode[:4], '*' * 16, self.vcode[-4:])
def get_remaining_time(self):
if self.paid_until:
return max((self.paid_until - datetime.datetime.utcnow()).total_seconds(), 0)
else:
return 0
# API cache entries
class APICache(models.Model):
url = models.URLField()
parameters = models.CharField(max_length=1024)
cached_until = models.DateTimeField()
text = models.TextField()
completed_ok = models.BooleanField()
# ---------------------------------------------------------------------------
# Events
class Event(models.Model):
user = models.ForeignKey(User)
issued = models.DateTimeField()
text = models.TextField()
class Meta:
ordering = ('-issued', '-id')
def get_age(self):
return (datetime.datetime.now() - self.issued).total_seconds()
# ---------------------------------------------------------------------------
# Corporations
class Corporation(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=64)
ticker = models.CharField(max_length=5, blank=True, null=True)
division1 = models.CharField(max_length=64, blank=True, null=True)
division2 = models.CharField(max_length=64, blank=True, null=True)
division3 = models.CharField(max_length=64, blank=True, null=True)
division4 = models.CharField(max_length=64, blank=True, null=True)
division5 = models.CharField(max_length=64, blank=True, null=True)
division6 = models.CharField(max_length=64, blank=True, null=True)
division7 = models.CharField(max_length=64, blank=True, null=True)
class Meta:
ordering = ('name',)
def __unicode__(self):
return '%s [%s]' % (self.name, self.ticker)
def get_total_balance(self):
return self.corpwallet_set.aggregate(Sum('balance'))['balance_sum']
# ---------------------------------------------------------------------------
# Corporation wallets
class CorpWallet(models.Model):
account_id = models.IntegerField(primary_key=True)
corporation = models.ForeignKey(Corporation)
account_key = models.IntegerField()
description = models.CharField(max_length=64)
balance = models.DecimalField(max_digits=18, decimal_places=2)
class Meta:
ordering = ('corporation', 'account_id')
def __unicode__(self):
return '%s [%s] %s' % (self.corporation.name, self.account_key, self.description)
# ---------------------------------------------------------------------------
# Characters
class Character(models.Model):
id = models.IntegerField(primary_key=True)
apikey = models.ForeignKey(APIKey, null=True, blank=True)
name = models.CharField(max_length=64)
corporation = models.ForeignKey(Corporation)
wallet_balance = models.DecimalField(max_digits=18, decimal_places=2)
cha_attribute = models.SmallIntegerField()
int_attribute = models.SmallIntegerField()
mem_attribute = models.SmallIntegerField()
per_attribute = models.SmallIntegerField()
wil_attribute = models.SmallIntegerField()
cha_bonus = models.SmallIntegerField()
int_bonus = models.SmallIntegerField()
mem_bonus = models.SmallIntegerField()
per_bonus = models.SmallIntegerField()
wil_bonus = models.SmallIntegerField()
clone_name = models.CharField(max_length=32)
clone_skill_points= models.IntegerField()
skills = models.ManyToManyField('Skill', related_name='learned_by', through='CharacterSkill')
skill_queue = models.ManyToManyField('Skill', related_name='training_by', through='SkillQueue')
# industry stuff
factory_cost = models.DecimalField(max_digits=8, decimal_places=2, default=0.0)
factory_per_hour = models.DecimalField(max_digits=8, decimal_places=2, default=0.0)
sales_tax = models.DecimalField(max_digits=3, decimal_places=2, default=1.0)
brokers_fee = models.DecimalField(max_digits=3, decimal_places=2, default=1.0)
class Meta:
ordering = ('name',)
def __unicode__(self):
return self.name
@models.permalink
def get_absolute_url(self):
return ('character', (), {
'character_name': self.name,
}
)
def get_short_clone_name(self):
return self.clone_name.replace('Clone Grade ', '')
def get_total_skill_points(self):
return CharacterSkill.objects.filter(character=self).aggregate(total_sp=Sum('points'))['total_sp']
class CharacterConfig(models.Model):
character = models.OneToOneField(Character, unique=True, primary_key=True, related_name='config')
is_public = models.BooleanField()
show_clone = models.BooleanField()
show_implants = models.BooleanField()
show_skill_queue = models.BooleanField()
show_wallet = models.BooleanField()
anon_key = models.CharField(max_length=16, blank=True, null=True)
def __unicode__(self):
return self.character.name
# Character skills
class CharacterSkill(models.Model):
character = models.ForeignKey('Character')
skill = models.ForeignKey('Skill')
level = models.SmallIntegerField()
points = models.IntegerField()
def __unicode__(self):
return '%s: %s (%s; %s SP)' % (self.character, self.skill.item.name, self.level, self.points)
def get_roman_level(self):
return ['', 'I', 'II', 'III', 'IV', 'V'][self.level]
# Skill queue
class SkillQueue(models.Model):
character = models.ForeignKey('Character')
skill = models.ForeignKey('Skill')
start_time = models.DateTimeField()
end_time = models.DateTimeField()
start_sp = models.IntegerField()
end_sp = models.IntegerField()
to_level = models.SmallIntegerField()
def __unicode__(self):
return '%s: %s %d, %d -> %d - Start: %s, End: %s' % (self.character.name, self.skill.item.name,
self.to_level, self.start_sp, self.end_sp, self.start_time, self.end_time)
class Meta:
ordering = ('start_time',)
def get_complete_percentage(self, now=None):
if now is None:
now = datetime.datetime.utcnow()
remaining = (self.end_time - now).total_seconds()
remain_sp = remaining / 60.0 * self.skill.get_sp_per_minute(self.character)
required_sp = self.skill.get_sp_at_level(self.to_level) - self.skill.get_sp_at_level(self.to_level - 1)
return round(100 - (remain_sp / required_sp * 100), 1)
def get_roman_level(self):
return ['', 'I', 'II', 'III', 'IV', 'V'][self.to_level]
def get_remaining(self):
remaining = (self.end_time - datetime.datetime.utcnow()).total_seconds()
return int(remaining)
# ---------------------------------------------------------------------------
# Regions
class Region(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=64)
def __unicode__(self):
return self.name
class Meta:
ordering = ('name'),
# Constellations
class Constellation(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=64)
region = models.ForeignKey(Region)
def __unicode__(self):
return self.name
class Meta:
ordering = ('name'),
# Systems
class System(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=32)
constellation = models.ForeignKey(Constellation)
def __unicode__(self):
return self.name
class Meta:
ordering = ('name'),
# ---------------------------------------------------------------------------
# Stations
numeral_map = zip(
(1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1),
('M', 'CM', 'D', 'CD', 'C', 'XC', 'L', 'XL', 'X', 'IX', 'V', 'IV', 'I')
)
def roman_to_int(n):
n = unicode(n).upper()
i = result = 0
for integer, numeral in numeral_map:
while n[i:i + len(numeral)] == numeral:
result += integer
i += len(numeral)
return result
class Station(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=128)
short_name = models.CharField(max_length=64, blank=True, null=True)
system = models.ForeignKey(System)
def __unicode__(self):
return self.name
# Build the short name when this object is saved
def save(self, *args, **kwargs):
self._make_shorter_name()
super(Station, self).save(*args, **kwargs)
def _make_shorter_name(self):
out = []
parts = self.name.split(' - ')
if len(parts) == 1:
self.short_name = self.name
else:
a_parts = parts[0].split()
# Change the roman annoyance to a proper digit
out.append('%s %s' % (a_parts[0], str(roman_to_int(a_parts[1]))))
# Moooon
if parts[1].startswith('Moon'):
out[0] = '%s-%s' % (out[0], parts[1][5:])
out.append(''.join(s[0] for s in parts[2].split()))
else:
out.append(''.join(s[0] for s in parts[1].split()))
self.short_name = ' - '.join(out)
# ---------------------------------------------------------------------------
# Market groups
class MarketGroup(MPTTModel):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=100)
parent = TreeForeignKey('self', blank=True, null=True, related_name='children')
def __unicode__(self):
return self.name
class MPTTMeta:
order_insertion_by = ['name']
# ---------------------------------------------------------------------------
# Item categories
class ItemCategory(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=64)
def __unicode__(self):
return self.name
# ---------------------------------------------------------------------------
# Item groups
class ItemGroup(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=64)
category = models.ForeignKey(ItemCategory)
def __unicode__(self):
return self.name
# ---------------------------------------------------------------------------
# Items
class Item(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=128)
item_group = models.ForeignKey(ItemGroup)
market_group = models.ForeignKey(MarketGroup, blank=True, null=True)
portion_size = models.IntegerField()
# 0.0025 -> 10,000,000,000
volume = models.DecimalField(max_digits=16, decimal_places=4, default=0)
sell_price = models.DecimalField(max_digits=15, decimal_places=2, default=0)
buy_price = models.DecimalField(max_digits=15, decimal_places=2, default=0)
def __unicode__(self):
return self.name
def get_volume(self, days=7):
iph_days = self.pricehistory_set.all()[:days]
agg = self.pricehistory_set.filter(pk__in=iph_days).aggregate(Sum('movement'))
if agg['movement__sum'] is None:
return Decimal('0')
else:
return Decimal(str(agg['movement__sum']))
# ---------------------------------------------------------------------------
# Skills
class Skill(models.Model):
CHARISMA_ATTRIBUTE = 164
INTELLIGENCE_ATTRIBUTE = 165
MEMORY_ATTRIBUTE = 166
PERCEPTION_ATTRIBUTE = 167
WILLPOWER_ATTRIBUTE = 168
ATTRIBUTE_CHOICES = (
(CHARISMA_ATTRIBUTE, 'Cha'),
(INTELLIGENCE_ATTRIBUTE, 'Int'),
(MEMORY_ATTRIBUTE, 'Mem'),
(PERCEPTION_ATTRIBUTE, 'Per'),
(WILLPOWER_ATTRIBUTE, 'Wil'),
)
ATTRIBUTE_MAP = {
CHARISMA_ATTRIBUTE: ('cha_attribute', 'cha_bonus'),
INTELLIGENCE_ATTRIBUTE: ('int_attribute', 'int_bonus'),
MEMORY_ATTRIBUTE: ('mem_attribute', 'mem_bonus'),
PERCEPTION_ATTRIBUTE: ('per_attribute', 'per_bonus'),
WILLPOWER_ATTRIBUTE: ('wil_attribute', 'wil_bonus'),
}
item = models.OneToOneField(Item, primary_key=True)
rank = models.SmallIntegerField()
primary_attribute = models.SmallIntegerField(choices=ATTRIBUTE_CHOICES)
secondary_attribute = models.SmallIntegerField(choices=ATTRIBUTE_CHOICES)
def __unicode__(self):
return '%s (Rank %d; %s/%s)' % (self.item.name, self.rank, self.get_primary_attribute_display(),
self.get_secondary_attribute_display())
def get_sp_at_level(self, level=5):
if level == 0:
return 0
else:
return int(math.ceil(2 ** ((2.5 * level) - 2.5) * 250 * self.rank))
def get_sp_per_minute(self, character):
pri_attrs = Skill.ATTRIBUTE_MAP[self.primary_attribute]
sec_attrs = Skill.ATTRIBUTE_MAP[self.secondary_attribute]
pri = getattr(character, pri_attrs[0]) + getattr(character, pri_attrs[1])
sec = getattr(character, sec_attrs[0]) + getattr(character, sec_attrs[1])
return pri + (sec / 2.0)
# ---------------------------------------------------------------------------
# Historical item price data
class PriceHistory(models.Model):
region = models.ForeignKey(Region)
item = models.ForeignKey(Item)
date = models.DateField()
minimum = models.DecimalField(max_digits=18, decimal_places=2)
maximum = models.DecimalField(max_digits=18, decimal_places=2)
average = models.DecimalField(max_digits=18, decimal_places=2)
movement = models.BigIntegerField()
orders = models.IntegerField()
class Meta:
ordering = ('-date',)
unique_together = ('region', 'item', 'date')
def __unicode__(self):
return '%s (%s)' % (self.item, self.date)
# ---------------------------------------------------------------------------
# Time frames
# TODO: rename this and implement (character, corp_wallet) assignment somehow
class Campaign(models.Model):
user = models.ForeignKey(User)
title = models.CharField(max_length=32)
slug = models.SlugField(max_length=32)
start_date = models.DateTimeField()
end_date = models.DateTimeField()
corp_wallets = models.ManyToManyField(CorpWallet, blank=True, null=True)
characters = models.ManyToManyField(Character, blank=True, null=True)
class Meta:
ordering = ('title',)
def __unicode__(self):
return self.title
def get_transactions_filter(self, transactions):
return transactions.filter(
Q(corp_wallet__in=self.corp_wallets.all()) |
(
Q(corp_wallet=None) &
Q(character__in=self.characters.all())
),
date__range=(self.start_date, self.end_date),
)
# ---------------------------------------------------------------------------
# Wallet transactions
class Transaction(models.Model):
station = models.ForeignKey(Station)
character = models.ForeignKey(Character)
item = models.ForeignKey(Item)
corp_wallet = models.ForeignKey(CorpWallet, null=True, blank=True)
transaction_id = models.BigIntegerField()
date = models.DateTimeField(db_index=True)
buy_transaction = models.BooleanField()
quantity = models.IntegerField()
price = models.DecimalField(max_digits=14, decimal_places=2)
total_price = models.DecimalField(max_digits=17, decimal_places=2)
# ---------------------------------------------------------------------------
# Market orders
class MarketOrder(models.Model):
order_id = models.BigIntegerField(primary_key=True)
station = models.ForeignKey(Station)
item = models.ForeignKey(Item)
character = models.ForeignKey(Character)
corp_wallet = models.ForeignKey(CorpWallet, null=True, blank=True)
escrow = models.DecimalField(max_digits=14, decimal_places=2)
price = models.DecimalField(max_digits=14, decimal_places=2)
total_price = models.DecimalField(max_digits=17, decimal_places=2)
buy_order = models.BooleanField()
volume_entered = models.IntegerField()
volume_remaining = models.IntegerField()
minimum_volume = models.IntegerField()
issued = models.DateTimeField(db_index=True)
expires = models.DateTimeField(db_index=True)
class Meta:
ordering = ('buy_order', 'item__name')
# ---------------------------------------------------------------------------
# Inventory flags
class InventoryFlag(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=64)
text = models.CharField(max_length=128)
def nice_name(self):
if self.name.startswith('HiSlot'):
return 'High Slot'
elif self.name.startswith('MedSlot'):
return 'Mid Slot'
elif self.name.startswith('LoSlot'):
return 'Low Slot'
elif self.name.startswith('RigSlot'):
return 'Rig Slot'
elif self.name == 'DroneBay':
return 'Drone Bay'
else:
return self.name
def sort_order(self):
if self.name.startswith('HiSlot'):
return 0
elif self.name.startswith('MedSlot'):
return 1
elif self.name.startswith('LoSlot'):
return 2
elif self.name.startswith('RigSlot'):
return 3
elif self.name.startswith('DroneBay'):
return 4
else:
return self.name
# ---------------------------------------------------------------------------
class Asset(MPTTModel):
id = models.BigIntegerField(primary_key=True)
parent = TreeForeignKey('self', blank=True, null=True, related_name='children')
character = models.ForeignKey(Character, blank=True, null=True)
corporation = models.ForeignKey(Corporation, blank=True, null=True)
system = models.ForeignKey(System, blank=True, null=True)
station = models.ForeignKey(Station, blank=True, null=True)
item = models.ForeignKey(Item)
name = models.CharField(max_length=128, blank=True, null=True)
inv_flag = models.ForeignKey(InventoryFlag)
quantity = models.IntegerField()
raw_quantity = models.IntegerField()
singleton = models.BooleanField()
def system_or_station(self):
if self.station is not None:
return self.station.name
elif self.system is not None:
return self.system.name
else:
return None
# def __unicode__(self):
# return '%s' % (self.name)
# ---------------------------------------------------------------------------
# Industry jobs
# fixme: implement POS support, oh god
#class IndustryJob(models.Model):
# job_id = models.IntegerField()
# station_id = models.ForeignKeyField(Station)
#
# install_time = models.DateTimeField()
# begin_time = models.DateTimeField()
# end_time = models.DateTimeField()
# ---------------------------------------------------------------------------
# Blueprints
class Blueprint(models.Model):
id = models.IntegerField(primary_key=True)
name = models.CharField(max_length=128)
item = models.ForeignKey(Item)
production_time = models.IntegerField()
productivity_modifier = models.IntegerField()
material_modifier = models.IntegerField()
waste_factor = models.IntegerField()
components = models.ManyToManyField(Item, related_name='component_of', through='BlueprintComponent')
class Meta:
ordering = ('name',)
def __unicode__(self):
return self.name
# ---------------------------------------------------------------------------
# Blueprint components
class BlueprintComponent(models.Model):
blueprint = models.ForeignKey(Blueprint)
item = models.ForeignKey(Item)
count = models.IntegerField()
needs_waste = models.BooleanField(default=True)
# ---------------------------------------------------------------------------
# Blueprint instances - an owned blueprint
class BlueprintInstance(models.Model):
user = models.ForeignKey(User)
blueprint = models.ForeignKey(Blueprint)
original = models.BooleanField()
material_level = models.IntegerField(default=0)
productivity_level = models.IntegerField(default=0)
class Meta:
ordering = ('blueprint',)#.item',)
def __unicode__(self):
if self.original:
return "%s (BPO, ML%s PL%s)" % (self.blueprint.name, self.material_level, self.productivity_level)
else:
return "%s (BPC, ML%s PL%s)" % (self.blueprint.name, self.material_level, self.productivity_level)
# Calculate production time, taking PL and skills into account
# TODO: fix this, skills not available
# TODO: take implants into account
def calc_production_time(self, runs=1):
# PTM = ProductionTimeModifier = (1 - (0.04 * IndustrySkill)) * ImplantModifier * ProductionSlotModifier
# ProductionTime (PL>=0) = BaseProductionTime * (1 - (ProductivityModifier / BaseProductionTime) * (PL / (1 + PL)) * PTM
# ProductionTime (PL<0) = BaseProductionTime * (1 - (ProductivityModifier / BaseProductionTime) * (PL - 1)) * PTM
PTM = (1 - (Decimal('0.04') * 5))#self.character.industry_skill)) # FIXME:implement implants/production slot modifiers
BPT = Decimal(self.blueprint.production_time)
BPM = self.blueprint.productivity_modifier
PL = Decimal(self.productivity_level)
if PL >= 0:
pt = BPT * (1 - (BPM / BPT) * (PL / (1 + PL))) * PTM
else:
pt = BPT * (1 - (BPM / BPT) * (PL - 1)) * PTM
pt *= runs
return pt.quantize(Decimal('0'), rounding=ROUND_UP)
# Calculate production cost, taking ML and skills into account
# TODO: fix this, skills not available
# TODO: move factory cost/etc to a model attached to the User table
def calc_production_cost(self, components=None, runs=1, use_sell=False, character=None):
total_cost = Decimal(0)
# Component costs
if components is None:
components = self._get_components(runs=runs)
for item, amt in components:
if use_sell is True:
total_cost += (Decimal(str(amt)) * item.sell_price)
else:
total_cost += (Decimal(str(amt)) * item.buy_price)
# Factory costs
if character is not None:
total_cost += character.factory_cost
total_cost += (character.factory_per_hour * (self.calc_production_time(runs=runs) / 3600))
# Sales tax
total_cost *= (1 + (character.sales_tax / 100))
# Broker's fee
total_cost *= (1 + (character.brokers_fee / 100))
# Run count
total_cost /= (self.blueprint.item.portion_size * runs)
return total_cost.quantize(Decimal('.01'), rounding=ROUND_UP)
# Get all components required for this item, adjusted for ML and relevant skills
# TODO: fix this, skills aren't currently available
def _get_components(self, components=None, runs=1):
PES = 5 #fixme: self.character.production_efficiency_skill
ML = self.material_level
WF = self.blueprint.waste_factor
comps = []
if components is None:
components = BlueprintComponent.objects.filter(blueprint=self.blueprint).select_related(depth=1)
for component in components:
if component.needs_waste:
amt = round(component.count * (1 + ((WF / 100.0) / (ML + 1)) + (0.25 - (0.05 * PES))))
else:
amt = component.count
comps.append((component.item, int(amt * runs)))
return comps