2018-10-26 23:42:53 +00:00
|
|
|
from django.db import models
|
|
|
|
from django.conf import settings
|
2019-02-06 20:54:50 +00:00
|
|
|
from django.urls import reverse
|
2018-11-22 02:09:30 +00:00
|
|
|
from sys import maxsize
|
2019-07-21 15:28:25 +00:00
|
|
|
import datetime
|
2019-08-19 21:54:17 +00:00
|
|
|
import enum
|
2018-10-26 23:42:53 +00:00
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
from GeoffreyApp.util import create_token, objects_list_to_json
|
2018-12-30 01:41:18 +00:00
|
|
|
|
2019-03-22 14:41:50 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
# Create your models here.
|
|
|
|
|
2019-08-19 21:54:17 +00:00
|
|
|
class PermissionLevel(enum.Enum):
|
|
|
|
ADMIN = enum.auto()
|
|
|
|
MOD = enum.auto()
|
|
|
|
PLAYER = enum.auto()
|
|
|
|
|
2018-12-02 00:25:53 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
class APIToken(models.Model):
|
|
|
|
key = models.CharField(default=create_token, max_length=25, unique=True)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Key used to access the Geoffrey API
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
name = models.CharField(max_length=50, blank=True)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Name of the key
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
commands_perm = models.BooleanField(default=False)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Permission to use the command api
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-12-30 01:41:18 +00:00
|
|
|
|
2019-08-19 21:54:17 +00:00
|
|
|
mod_commands_perm = models.BooleanField(default=False)
|
|
|
|
"""
|
|
|
|
Permission to use mod commands
|
|
|
|
"""
|
|
|
|
admin_commands_perm = models.BooleanField(default=False)
|
|
|
|
"""
|
|
|
|
Permission to use admin commands
|
|
|
|
"""
|
|
|
|
|
2019-09-17 16:23:47 +00:00
|
|
|
model_api_perm = models.BooleanField(default=False)
|
|
|
|
"""
|
|
|
|
Permission to access the model api
|
|
|
|
"""
|
|
|
|
|
2019-08-19 21:54:17 +00:00
|
|
|
def has_command_permission(self, permission_level):
|
|
|
|
if permission_level == PermissionLevel.ADMIN:
|
|
|
|
return self.admin_commands_perm
|
|
|
|
elif permission_level == PermissionLevel.MOD:
|
|
|
|
return self.admin_commands_perm
|
|
|
|
elif permission_level == PermissionLevel.PLAYER:
|
|
|
|
return self.commands_perm
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
def __str__(self):
|
|
|
|
if len(self.name):
|
|
|
|
return "{}: {}".format(self.name, self.key)
|
|
|
|
else:
|
|
|
|
return self.key
|
|
|
|
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
class Player(models.Model):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
Model of a Player
|
|
|
|
"""
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
name = models.CharField(max_length=30, unique=True)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
In Game Username
|
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
mc_uuid = models.CharField(max_length=36, unique=True)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Minecraft UUID
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
discord_uuid = models.CharField(max_length=50, unique=True)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Discord UUID
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-01-12 21:06:06 +00:00
|
|
|
@property
|
|
|
|
def loc_count(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
Number of locations the player is an owner of
|
|
|
|
"""
|
2019-01-12 21:06:06 +00:00
|
|
|
return Location.objects.filter(owner=self).count()
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
@property
|
|
|
|
def json(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
JSON representation of the Player
|
|
|
|
|
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
{
|
|
|
|
"name" : "self.name",
|
|
|
|
"mc_uuid": "self.mc_uuid",
|
|
|
|
"discord_uuid": "self.discord_uuid",
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-01-06 21:24:47 +00:00
|
|
|
return {"name": self.name,
|
|
|
|
"mc_uuid": self.mc_uuid,
|
|
|
|
"discord_uuid": self.discord_uuid
|
2019-01-04 17:20:24 +00:00
|
|
|
}
|
2018-10-26 23:42:53 +00:00
|
|
|
|
2019-04-13 01:04:13 +00:00
|
|
|
@property
|
|
|
|
def link(self):
|
|
|
|
"""
|
|
|
|
href to the player page
|
|
|
|
"""
|
|
|
|
return reverse("GeoffreyPlayerInfo", kwargs={"id": self.id})
|
|
|
|
|
2018-12-14 01:58:59 +00:00
|
|
|
def __str__(self):
|
|
|
|
return self.name
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
class Location(models.Model):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""Model of a Location"""
|
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
info_page = None
|
|
|
|
"""
|
|
|
|
Name of the info page view
|
|
|
|
"""
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
DIMENSIONS = (
|
|
|
|
('O', 'Overworld'),
|
|
|
|
('N', 'Nether'),
|
|
|
|
('E', 'The End')
|
|
|
|
)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
Possible dimensions for a location to be in
|
|
|
|
"""
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
name = models.CharField(max_length=128, unique=True)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Name of the location
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
x_coord = models.IntegerField()
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
X Position
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
z_coord = models.IntegerField()
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Z Position
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
dimension = models.CharField(max_length=1, choices=DIMENSIONS)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
Dimension of Location
|
|
|
|
"""
|
2018-10-26 23:42:53 +00:00
|
|
|
|
2019-01-31 20:07:25 +00:00
|
|
|
owner = models.ManyToManyField(Player)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Owner of Location
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-10-26 23:42:53 +00:00
|
|
|
|
2019-01-12 21:06:06 +00:00
|
|
|
@property
|
2019-03-22 14:41:50 +00:00
|
|
|
def position(self):
|
|
|
|
"""
|
|
|
|
Formatted position of the location
|
|
|
|
"""
|
2019-01-14 01:27:48 +00:00
|
|
|
return "(x={}, z={})".format(self.x_coord, self.z_coord)
|
2019-01-12 21:06:06 +00:00
|
|
|
|
2019-01-14 20:22:18 +00:00
|
|
|
@property
|
|
|
|
def tunnel(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
The tunnel associated if this location, None if no tunnel exists
|
|
|
|
"""
|
2019-01-14 20:22:18 +00:00
|
|
|
try:
|
|
|
|
tunnel = Tunnel.objects.get(location=self)
|
|
|
|
except Tunnel.DoesNotExist:
|
|
|
|
tunnel = None
|
|
|
|
|
|
|
|
return tunnel
|
|
|
|
|
2019-01-31 20:07:25 +00:00
|
|
|
@property
|
|
|
|
def get_owners(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
List of all the owners of the location
|
|
|
|
"""
|
2019-01-31 20:07:25 +00:00
|
|
|
owner_list = []
|
|
|
|
for owner in self.owner.all():
|
|
|
|
owner_list.append(owner.json)
|
|
|
|
|
|
|
|
return owner_list
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
@property
|
|
|
|
def json(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
JSON representation of the location
|
|
|
|
|
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
{
|
|
|
|
"type": "Base",
|
|
|
|
"name": "Location",
|
|
|
|
"x_coord": 0,
|
|
|
|
"z_coord": 0,
|
|
|
|
"dimension": "O",
|
|
|
|
"owner": [],
|
|
|
|
"tunnel": {},
|
|
|
|
"link": "/GeoffreyApp/Base/1"
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
return {"type": self.loc_type,
|
2019-01-06 21:24:47 +00:00
|
|
|
"name": self.name,
|
2019-01-04 17:20:24 +00:00
|
|
|
"x_coord": self.x_coord,
|
|
|
|
"z_coord": self.z_coord,
|
|
|
|
"dimension": self.dimension,
|
2019-01-31 20:07:25 +00:00
|
|
|
"owner": self.get_owners,
|
2019-03-22 14:41:50 +00:00
|
|
|
"location": self.position,
|
2019-02-06 20:54:50 +00:00
|
|
|
"tunnel": None if self.tunnel is None else self.tunnel.tunnel_str,
|
|
|
|
"link": self.link
|
2019-01-04 17:20:24 +00:00
|
|
|
}
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-01-14 01:27:48 +00:00
|
|
|
@property
|
|
|
|
def loc_type(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
The name of the location type
|
|
|
|
"""
|
2019-02-06 20:54:50 +00:00
|
|
|
str = self.loc_child_obj.__class__.__name__
|
|
|
|
|
|
|
|
return str
|
|
|
|
|
|
|
|
@property
|
|
|
|
def link(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
href to the location page
|
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
child = self.loc_child_obj
|
|
|
|
|
2019-04-10 22:31:52 +00:00
|
|
|
if child is not self:
|
|
|
|
return reverse(child.info_page, kwargs={"id": child.id})
|
|
|
|
else:
|
|
|
|
return reverse(self.info_page, kwargs={"id": self.id})
|
2019-02-06 20:54:50 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def loc_child_obj(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
Child object
|
|
|
|
"""
|
2019-01-14 01:27:48 +00:00
|
|
|
if hasattr(self, "shop"):
|
2019-02-06 20:54:50 +00:00
|
|
|
return self.shop
|
2019-01-14 01:27:48 +00:00
|
|
|
elif hasattr(self, "base"):
|
2019-02-06 20:54:50 +00:00
|
|
|
return self.base
|
2019-02-02 22:31:02 +00:00
|
|
|
elif hasattr(self, "town"):
|
2019-02-06 20:54:50 +00:00
|
|
|
return self.town
|
2019-03-02 17:48:28 +00:00
|
|
|
elif hasattr(self, "publicfarm"):
|
|
|
|
return self.publicfarm
|
2019-04-10 23:04:20 +00:00
|
|
|
elif hasattr(self, "market"):
|
|
|
|
return self.market
|
2019-05-13 14:53:01 +00:00
|
|
|
elif hasattr(self, "attraction"):
|
|
|
|
return self.attraction
|
2019-09-28 02:49:54 +00:00
|
|
|
elif hasattr(self, "pointofintrest"):
|
|
|
|
return self.pointofintrest
|
2019-01-14 01:27:48 +00:00
|
|
|
else:
|
2019-02-06 20:54:50 +00:00
|
|
|
return self
|
2019-01-14 01:27:48 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def dynmap_url(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
Link to the location on the dynmap, none if there is no dynmap
|
|
|
|
"""
|
|
|
|
|
2019-01-14 01:27:48 +00:00
|
|
|
base_url = getattr(settings, "GEOFFREY_DYNMAP_BASE_URL")
|
|
|
|
world_name = getattr(settings, "GEOFFREY_DYNMAP_WORLD_NAME")
|
2019-09-29 19:55:28 +00:00
|
|
|
if base_url:
|
2019-01-14 01:27:48 +00:00
|
|
|
url = base_url + "/?worldname={}&mapname=surface&zoom=4&x={}&y=65&z={}".format(world_name, self.x_coord,
|
|
|
|
self.z_coord)
|
|
|
|
return url
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
|
2018-12-30 01:41:18 +00:00
|
|
|
def __str__(self):
|
2019-04-10 23:04:20 +00:00
|
|
|
return "%s: %s" % (self.loc_child_obj.__class__.__name__, self.name)
|
2018-12-30 01:41:18 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
|
2019-04-13 00:39:25 +00:00
|
|
|
class PointOfInterest(Location):
|
|
|
|
info_page = "GeoffreyPointOfInterest"
|
|
|
|
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
class Shop(Location):
|
2019-04-10 22:31:52 +00:00
|
|
|
info_page = "GeoffreyShopInfo"
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
class Base(Location):
|
2019-04-10 22:31:52 +00:00
|
|
|
info_page = "GeoffreyBaseInfo"
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
class Town(Location):
|
2019-04-10 22:31:52 +00:00
|
|
|
info_page = "GeoffreyTownInfo"
|
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
residents = models.ManyToManyField(Player)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
Players who are members of the town
|
|
|
|
"""
|
2019-02-02 22:31:02 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def get_residents(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
List of residents in the town in JSON farm
|
|
|
|
"""
|
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
residents = self.residents.all()
|
|
|
|
|
|
|
|
return objects_list_to_json(residents)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def json(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
JSON representation of the town
|
|
|
|
|
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
{
|
|
|
|
"type": "Town",
|
|
|
|
"name": "Location",
|
|
|
|
"x_coord": 0,
|
|
|
|
"z_coord": 0,
|
|
|
|
"dimension": "O",
|
|
|
|
"owner": [],
|
|
|
|
"tunnel": {},
|
2019-04-10 23:04:20 +00:00
|
|
|
"link": "/GeoffreyApp/Town/1",
|
2019-03-22 14:41:50 +00:00
|
|
|
"residents": []
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
json = super().json
|
|
|
|
|
2019-02-06 20:54:50 +00:00
|
|
|
json["residents"] = self.get_residents
|
2019-02-02 22:31:02 +00:00
|
|
|
|
|
|
|
return json
|
|
|
|
|
2019-04-10 22:31:52 +00:00
|
|
|
|
|
|
|
class Market(Location):
|
|
|
|
info_page = "GeoffreyMarketInfo"
|
2019-02-06 20:54:50 +00:00
|
|
|
|
2019-04-10 23:04:20 +00:00
|
|
|
def get_shops(self, market_radius=100, limit=10):
|
2019-05-11 16:46:30 +00:00
|
|
|
x = int(self.x_coord)
|
|
|
|
z = int(self.z_coord)
|
|
|
|
shops = Shop.objects.filter(x_coord__range=(x - market_radius, x + market_radius),
|
|
|
|
z_coord__range=(z - market_radius, z + market_radius)
|
2019-04-10 23:04:20 +00:00
|
|
|
)[:limit]
|
|
|
|
|
|
|
|
return shops
|
|
|
|
|
|
|
|
@property
|
|
|
|
def json(self):
|
|
|
|
"""
|
|
|
|
JSON representation of the market
|
2019-05-11 16:21:00 +00:00
|
|
|
|
2019-04-10 23:04:20 +00:00
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
{
|
2019-09-21 14:13:57 +00:00
|
|
|
"type": "Market",
|
2019-04-10 23:04:20 +00:00
|
|
|
"name": "Location",
|
|
|
|
"x_coord": 0,
|
|
|
|
"z_coord": 0,
|
|
|
|
"dimension": "O",
|
|
|
|
"owner": [],
|
|
|
|
"tunnel": {},
|
|
|
|
"link": "/GeoffreyApp/Market/1",
|
|
|
|
"shops": []
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
json = super().json
|
|
|
|
|
|
|
|
json["shops"] = objects_list_to_json(self.get_shops(limit=10))
|
|
|
|
|
|
|
|
return json
|
|
|
|
|
2019-02-02 22:31:02 +00:00
|
|
|
|
2019-03-02 17:48:28 +00:00
|
|
|
class PublicFarm(Location):
|
2019-04-10 22:31:52 +00:00
|
|
|
info_page = "GeoffreyPublicFarmInfo"
|
2019-03-02 17:48:28 +00:00
|
|
|
|
|
|
|
|
2019-05-12 16:23:59 +00:00
|
|
|
class Attraction(Location):
|
|
|
|
info_page = "GeoffreyAttractionInfo"
|
|
|
|
|
|
|
|
|
2019-03-02 17:48:28 +00:00
|
|
|
class Resource(models.Model):
|
|
|
|
farm = models.ForeignKey(PublicFarm, related_name="resource", on_delete=models.CASCADE)
|
|
|
|
resource_name = models.CharField(max_length=128)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def json(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-09-21 14:13:57 +00:00
|
|
|
JSON representation of the Resource
|
2019-03-22 14:41:50 +00:00
|
|
|
|
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
{
|
|
|
|
"name": "Dirt"
|
|
|
|
"farm_id": 1
|
|
|
|
}
|
|
|
|
"""
|
2019-03-02 17:48:28 +00:00
|
|
|
return {"name": self.resource_name,
|
|
|
|
"farm_id": self.farm_id
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
class ItemListing(models.Model):
|
|
|
|
item_name = models.CharField(max_length=128)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Name of the item
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
price = models.IntegerField()
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Number of diamonds per amount of items
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
amount = models.IntegerField()
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Number of items
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2019-01-04 20:39:53 +00:00
|
|
|
date_restocked = models.DateTimeField(auto_now=True)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Datetime the item was last restocked
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
shop = models.ForeignKey(Shop, related_name="shop_selling", on_delete=models.CASCADE)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Shop the item is sold at
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-10-26 23:42:53 +00:00
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
@property
|
|
|
|
def normalized_price(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
normalized price, price/amount
|
|
|
|
"""
|
|
|
|
|
2018-11-22 02:09:30 +00:00
|
|
|
if self.amount == 0:
|
|
|
|
return maxsize
|
|
|
|
else:
|
2019-03-22 14:41:50 +00:00
|
|
|
return self.price / self.amount
|
2018-11-22 02:09:30 +00:00
|
|
|
|
2019-07-21 15:28:25 +00:00
|
|
|
@property
|
|
|
|
def number_of_days_since_restocked(self):
|
|
|
|
"""
|
|
|
|
days since this item was restocked
|
|
|
|
"""
|
|
|
|
days = (datetime.datetime.now().astimezone() - self.date_restocked.astimezone()).days
|
|
|
|
|
|
|
|
return days
|
|
|
|
|
2019-01-04 17:20:24 +00:00
|
|
|
@property
|
|
|
|
def json(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
JSON representation of the item
|
|
|
|
|
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
{
|
|
|
|
"item_name": "dirt",
|
|
|
|
"price": 1,
|
|
|
|
"amount": 1,
|
|
|
|
"date_restocked": 1553264508,
|
2019-07-21 15:28:25 +00:00
|
|
|
"days_since_restock": 10,
|
2019-03-22 14:41:50 +00:00
|
|
|
"normalized_price": 1,
|
|
|
|
"shop": {}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
2019-01-04 17:20:24 +00:00
|
|
|
return {"item_name": self.item_name,
|
|
|
|
"price": self.price,
|
|
|
|
"amount": self.amount,
|
2019-03-22 14:41:50 +00:00
|
|
|
"date_restocked": self.date_restocked.timestamp(),
|
2019-07-21 15:28:25 +00:00
|
|
|
"days_since_restock": self.number_of_days_since_restocked,
|
2019-01-04 17:20:24 +00:00
|
|
|
"normalized_price": self.normalized_price,
|
|
|
|
"shop": self.shop.json,
|
|
|
|
}
|
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
def __str__(self):
|
|
|
|
return "Item: %d %s for %d" % (self.amount, self.item_name, self.amount)
|
|
|
|
|
|
|
|
|
|
|
|
class Tunnel(models.Model):
|
|
|
|
TUNNEL_NAMES = (
|
2019-01-11 22:40:12 +00:00
|
|
|
('N', getattr(settings, 'GEOFFREY_NORTH_TUNNEL', '')),
|
|
|
|
('E', getattr(settings, 'GEOFFREY_EAST_TUNNEL', '')),
|
|
|
|
('S', getattr(settings, 'GEOFFREY_SOUTH_TUNNEL', '')),
|
|
|
|
('W', getattr(settings, 'GEOFFREY_WEST_TUNNEL', ''))
|
2018-10-26 23:42:53 +00:00
|
|
|
)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Tunnel Direction
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
tunnel_number = models.IntegerField()
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Tunnel coordinate
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
|
2018-10-26 23:42:53 +00:00
|
|
|
tunnel_direction = models.CharField(max_length=1, choices=TUNNEL_NAMES)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2019-01-11 22:40:12 +00:00
|
|
|
Tunnel Direction
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
location = models.ForeignKey(Location, related_name="tunnel_location", on_delete=models.CASCADE)
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
Location that the tunnel is connected to
|
|
|
|
"""
|
2018-10-26 23:42:53 +00:00
|
|
|
|
|
|
|
def __str__(self):
|
2019-01-14 20:22:18 +00:00
|
|
|
return "Tunnel: %s %d" % (self.get_tunnel_direction_display(), self.tunnel_number)
|
2018-12-18 18:13:14 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def json(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
JSON representation of the tunnel`
|
|
|
|
|
|
|
|
.. code-block:: json
|
|
|
|
|
|
|
|
{
|
|
|
|
"location_name": "Base",
|
|
|
|
"tunnel_direction": "N",
|
|
|
|
"tunnel_number": 500
|
|
|
|
}
|
|
|
|
"""
|
2019-01-06 21:24:47 +00:00
|
|
|
return {"location_name": self.location.name,
|
2019-01-14 20:22:18 +00:00
|
|
|
"tunnel_direction": self.get_tunnel_direction_display(),
|
2019-01-04 17:20:24 +00:00
|
|
|
"tunnel_number": self.tunnel_number
|
|
|
|
}
|
2019-01-14 20:22:18 +00:00
|
|
|
|
|
|
|
@property
|
|
|
|
def tunnel_str(self):
|
2019-03-22 14:41:50 +00:00
|
|
|
"""
|
|
|
|
formatted tunnel string
|
|
|
|
"""
|
2019-01-14 20:22:18 +00:00
|
|
|
return "{} {}".format(self.get_tunnel_direction_display(), self.tunnel_number)
|