db update script and some fixes
This commit is contained in:
parent
aa9fda93c0
commit
1516ac2c51
|
@ -71,11 +71,6 @@ def user_registered_sighandler(app, user, confirm_token):
|
||||||
@app.before_first_request
|
@app.before_first_request
|
||||||
def before_first_request():
|
def before_first_request():
|
||||||
db.create_all()
|
db.create_all()
|
||||||
print("""
|
|
||||||
=========================
|
|
||||||
TEST
|
|
||||||
========================
|
|
||||||
""")
|
|
||||||
user_datastore.find_or_create_role(name='admin', description='Role for administrators')
|
user_datastore.find_or_create_role(name='admin', description='Role for administrators')
|
||||||
user_datastore.find_or_create_role(name='user', description='Role for all users.')
|
user_datastore.find_or_create_role(name='user', description='Role for all users.')
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
|
@ -34,7 +34,13 @@
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Costs</th>
|
<th>Costs</th>
|
||||||
<td>{{pitstop.costs}} €</td>
|
<td>
|
||||||
|
{% if pitstop.costs %}
|
||||||
|
{{pitstop.costs}} €
|
||||||
|
{% else %}
|
||||||
|
-- €
|
||||||
|
{% endif %}
|
||||||
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
{% if loop.first %}
|
{% if loop.first %}
|
||||||
|
|
|
@ -162,11 +162,11 @@
|
||||||
)
|
)
|
||||||
}}
|
}}
|
||||||
</div>
|
</div>
|
||||||
{{ tab_script('vehicle_' + vehicle.id + '_' + consumable.id + '_tabs') }}
|
{{ tab_script('vehicle_' + vehicle.id|string + '_' + consumable.id|string + '_tabs') }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
{{ tab_script('vehicle_' + vehicle.id + '_tabs') }}
|
{{ tab_script('vehicle_' + vehicle.id|string + '_tabs') }}
|
||||||
</div>
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import logging
|
import logging
|
||||||
from datetime import date
|
from datetime import date
|
||||||
from dis import code_info
|
|
||||||
|
|
||||||
from rollerverbrauch.entities import \
|
from rollerverbrauch.entities import \
|
||||||
Pitstop
|
Pitstop
|
||||||
|
@ -26,7 +25,6 @@ class ConsumableStats:
|
||||||
self.overall_amount += pitstop.amount
|
self.overall_amount += pitstop.amount
|
||||||
self.amounts.append(StatsEvent(pitstop.date, pitstop.amount))
|
self.amounts.append(StatsEvent(pitstop.date, pitstop.amount))
|
||||||
self.average_amount_fuelled = self.overall_amount / pitstop_count
|
self.average_amount_fuelled = self.overall_amount / pitstop_count
|
||||||
print(self.amounts)
|
|
||||||
if pitstop_count > 1:
|
if pitstop_count > 1:
|
||||||
overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer
|
overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer
|
||||||
self.average_distance = overall_distance / (pitstop_count - 1)
|
self.average_distance = overall_distance / (pitstop_count - 1)
|
||||||
|
@ -57,7 +55,8 @@ class VehicleStats:
|
||||||
if pitstop_count > 0:
|
if pitstop_count > 0:
|
||||||
for pitstop in vehicle.pitstops:
|
for pitstop in vehicle.pitstops:
|
||||||
self.odometers.append(StatsEvent(pitstop.date, pitstop.odometer))
|
self.odometers.append(StatsEvent(pitstop.date, pitstop.odometer))
|
||||||
self.overall_costs += pitstop.costs
|
if pitstop.costs is not None:
|
||||||
|
self.overall_costs += pitstop.costs
|
||||||
|
|
||||||
if pitstop_count > 1:
|
if pitstop_count > 1:
|
||||||
self.overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer
|
self.overall_distance = vehicle.pitstops[-1].odometer - vehicle.pitstops[0].odometer
|
||||||
|
|
|
@ -0,0 +1,28 @@
|
||||||
|
CREATE TABLE IF NOT EXISTS `consumable` (
|
||||||
|
`id` int(11) NOT NULL AUTO_INCREMENT,
|
||||||
|
`name` varchar(255) DEFAULT NULL,
|
||||||
|
`unit` varchar(255) DEFAULT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `name` (`name`)
|
||||||
|
) ENGINE=InnoDB AUTO_INCREMENT=31 DEFAULT CHARSET=latin1;
|
||||||
|
|
||||||
|
INSERT INTO `consumable`(`id`, `name`, `unit`) VALUES (1, 'Super E5', 'l');
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS `vehicles_consumables` (
|
||||||
|
`vehicle_id` int(11) DEFAULT NULL,
|
||||||
|
`consumable_id` int(11) DEFAULT NULL,
|
||||||
|
KEY `vehicle_id` (`vehicle_id`),
|
||||||
|
KEY `consumable_id` (`consumable_id`),
|
||||||
|
CONSTRAINT `vehicles_consumables_ibfk_1` FOREIGN KEY (`vehicle_id`) REFERENCES `vehicle` (`id`),
|
||||||
|
CONSTRAINT `vehicles_consumables_ibfk_2` FOREIGN KEY (`consumable_id`) REFERENCES `consumable` (`id`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
|
||||||
|
|
||||||
|
ALTER TABLE `pitstop` ADD COLUMN `costs` decimal(5,2) DEFAULT NULL;
|
||||||
|
|
||||||
|
ALTER TABLE `pitstop` CHANGE `litres` `amount`;
|
||||||
|
|
||||||
|
ALTER TABLE `pitstop` ADD COLUMN `consumable_id` int(11);
|
||||||
|
ALTER TABLE `pitstop` ADD FOREIGN KEY (`consumable_id`) REFERENCES `consumable` (`id`);
|
||||||
|
UPDATE `pitstop` set `consumable_id`=1;
|
||||||
|
|
||||||
|
INSERT INTO `vehicles_consumables`(`vehicle_id`, `consumable_id`) SELECT `id`, 1 FROM `vehicle`;
|
Loading…
Reference in New Issue