# Path: srs/models.py
# class Allyteam(models.Model):
#     numallies = models.IntegerField()
#     startrectbottom = models.FloatField(blank=True, null=True)
#     startrectleft = models.FloatField(blank=True, null=True)
#     startrectright = models.FloatField(blank=True, null=True)
#     startrecttop = models.FloatField(blank=True, null=True)
#     winner = models.BooleanField(default=False)
#     replay = models.ForeignKey(Replay, on_delete=CASCADE)
#     num = models.SmallIntegerField()
# 
#     def __unicode__(self):
#         return "Allyteam({}) win:{}".format(self.id, self.winner)
# 
# class Player(models.Model):
#     account = models.ForeignKey(PlayerAccount, blank=True, null=True, on_delete=CASCADE)
#     name = models.CharField(max_length=128, db_index=True)
#     rank = models.SmallIntegerField()
#     skill = models.CharField(max_length=16, blank=True)
#     skilluncertainty = models.SmallIntegerField(default=-1, blank=True)
#     spectator = models.BooleanField(default=False)
#     team = models.ForeignKey("Team", blank=True, null=True, on_delete=CASCADE)
#     replay = models.ForeignKey(Replay, on_delete=CASCADE)
#     startposx = models.FloatField(blank=True, null=True)
#     startposy = models.FloatField(blank=True, null=True)
#     startposz = models.FloatField(blank=True, null=True)
# 
#     def __unicode__(self):
#         return "Player({}, {})".format(self.id, self.name)
# 
#     def get_absolute_url(self):
#         return reverse("srs/player", args=[self.account.accountid])
# 
#     class Meta:
#         ordering = ["name"]


import json
import logging
import pprint
import random
import sys
import urllib.parse
import urllib.request
import requests
from os.path import exists as path_exists, join as path_join
from shutil import copyfile
from django.conf import settings
from PIL import Image, ImageColor, ImageDraw, ImageFont
from .models import Allyteam, Player
            map_px_x = replay.map_info.width
            map_px_y = replay.map_info.height
        else:
            # springfiles.springrts.com returnd Spring Map Size
            map_px_x = replay.map_info.width * 512
            map_px_y = replay.map_info.height * 512

        map_img_mult_x = map_px_x / full_img_x
        map_img_mult_y = map_px_y / full_img_y

        #
        # create start boxes
        #
        allyteams = Allyteam.objects.filter(
            replay=replay,
            startrectleft__isnull=False,
            startrecttop__isnull=False,
            startrectright__isnull=False,
            startrectbottom__isnull=False,
        )
        if allyteams.exists():
            # 6 defined colors
            colors = [
                (200, 0, 0),
                (0, 200, 0),
                (0, 0, 200),
                (200, 200, 0),
                (200, 0, 200),
                (0, 200, 200),
            ]

# Path: srs/models.py
# class Allyteam(models.Model):
#     numallies = models.IntegerField()
#     startrectbottom = models.FloatField(blank=True, null=True)
#     startrectleft = models.FloatField(blank=True, null=True)
#     startrectright = models.FloatField(blank=True, null=True)
#     startrecttop = models.FloatField(blank=True, null=True)
#     winner = models.BooleanField(default=False)
#     replay = models.ForeignKey(Replay, on_delete=CASCADE)
#     num = models.SmallIntegerField()
# 
#     def __unicode__(self):
#         return "Allyteam({}) win:{}".format(self.id, self.winner)
# 
# class Player(models.Model):
#     account = models.ForeignKey(PlayerAccount, blank=True, null=True, on_delete=CASCADE)
#     name = models.CharField(max_length=128, db_index=True)
#     rank = models.SmallIntegerField()
#     skill = models.CharField(max_length=16, blank=True)
#     skilluncertainty = models.SmallIntegerField(default=-1, blank=True)
#     spectator = models.BooleanField(default=False)
#     team = models.ForeignKey("Team", blank=True, null=True, on_delete=CASCADE)
#     replay = models.ForeignKey(Replay, on_delete=CASCADE)
#     startposx = models.FloatField(blank=True, null=True)
#     startposy = models.FloatField(blank=True, null=True)
#     startposz = models.FloatField(blank=True, null=True)
# 
#     def __unicode__(self):
#         return "Player({}, {})".format(self.id, self.name)
# 
#     def get_absolute_url(self):
#         return reverse("srs/player", args=[self.account.accountid])
# 
#     class Meta:
#         ordering = ["name"]


# Path: srs/springmaps.py
import json
import logging
import pprint
import random
import sys
import urllib.parse
import urllib.request
import requests
from os.path import exists as path_exists, join as path_join
from shutil import copyfile
from django.conf import settings
from PIL import Image, ImageColor, ImageDraw, ImageFont
from .models import Allyteam, Player

            map_px_x = replay.map_info.width
            map_px_y = replay.map_info.height
        else:
            # springfiles.springrts.com returnd Spring Map Size
            map_px_x = replay.map_info.width * 512
            map_px_y = replay.map_info.height * 512

        map_img_mult_x = map_px_x / full_img_x
        map_img_mult_y = map_px_y / full_img_y

        #
        # create start boxes
        #
        allyteams = Allyteam.objects.filter(
            replay=replay,
            startrectleft__isnull=False,
            startrecttop__isnull=False,
            startrectright__isnull=False,
            startrectbottom__isnull=False,
        )
        if allyteams.exists():
            # 6 defined colors
            colors = [
                (200, 0, 0),
                (0, 200, 0),
                (0, 0, 200),
                (200, 200, 0),
                (200, 0, 200),
                (0, 200, 200),
            ]

            if Allyteam.objects.filter(replay=replay).count() > 6: