# Path: quads/tools/simple_table_generator.py
# def generator(_host_file, _days, _month, _year, _gentime):
#     if _host_file:
#         with open(_host_file, "r") as f:
#             reader = csv.reader(f)
#             hosts = list(reader)
#     else:
#         hosts = sorted(Host.objects(retired=False, broken=False), key=lambda x: x.name)
# 
#     lines = []
#     __days = []
#     non_allocated_count = 0
#     all_samples = []
#     all_samples.extend(range(129296, 129510))
#     all_samples.extend(range(128000, 128252))
#     samples = random.sample(all_samples, 100)
#     exclude = [129401, 129484]
#     emojis = [emoji for emoji in samples if emoji not in exclude]
#     colors = [random_color() for _ in range(100)]
#     colors[0] = "#A9A9A9"
#     for i, host in enumerate(hosts):
#         line = {"hostname": host.name}
#         __days = []
#         for j in range(1, _days + 1):
#             cell_date = "%s-%.2d-%.2d 01:00" % (_year, _month, j)
#             cell_time = datetime.strptime(cell_date, "%Y-%m-%d %H:%M")
#             schedule = Schedule.current_schedule(host=host, date=cell_time).first()
#             if schedule:
#                 chosen_color = schedule.cloud.name[5:]
#             else:
#                 non_allocated_count += 1
#                 chosen_color = "01"
#             _day = {
#                 "day": j,
#                 "chosen_color": chosen_color,
#                 "emoji": "&#%s;" % emojis[int(chosen_color) - 1],
#                 "color": colors[int(chosen_color) - 1],
#                 "cell_date": cell_date,
#                 "cell_time": cell_time,
#             }
# 
#             if schedule:
#                 cloud = (
#                     CloudHistory.objects(
#                         __raw__={
#                             "_id": {"$lt": schedule.id},
#                             "name": schedule.cloud.name,
#                         }
#                     )
#                     .order_by("-_id")
#                     .first()
#                 )
#                 _day["display_description"] = cloud.description
#                 _day["display_owner"] = cloud.owner
#                 _day["display_ticket"] = cloud.ticket
#             __days.append(_day)
# 
#         line["days"] = __days
#         lines.append(line)
# 
#     total_hosts = len(hosts)
#     total_use = Schedule.current_schedule().count()
#     utilization = 100 - (non_allocated_count * 100 // (_days * total_hosts))
#     utilization_daily = total_use * 100 // total_hosts
#     with open(os.path.join(Config.TEMPLATES_PATH, "simple_table_emoji")) as _file:
#         template = Template(_file.read())
#     content = template.render(
#         gentime=_gentime,
#         _days=_days,
#         lines=lines,
#         utilization=utilization,
#         utilization_daily=utilization_daily,
#         total_use=total_use,
#         total_hosts=total_hosts,
#     )
# 
#     return content
# 
# Path: quads/config.py
# DEFAULT_CONF_PATH = os.path.join(os.path.dirname(__file__), "../conf/quads.yml")
#     LOGFMT = "%(asctime)-12s : %(levelname)-8s - %(message)s"
#     STDFMT = "- %(levelname)-8s - %(message)s"
#     API = "v2"
#     FPING_TIMEOUT = 10000
#     QUADSVERSION = "1.1.6"
#     QUADSCODENAME = "gaúcho"
#     SUPPORTED = [
#         "fc640",
#         "r620",
#         "r630",
#         "r640",
#         "640",
#         "r650",
#         "650",
#         "r720",
#         "r730xd",
#         "r930",
#         "r730",
#         "r740xd",
#         "740xd",
#         "r750xd",
#         "r750",
#         "750",
#         "r720xd",
#         "7425",
#         "7525",
#     ]
#     OFFSETS = {"em1": 0, "em2": 1, "em3": 2, "em4": 3, "em5": 4}
#     TEMPLATES_PATH = os.path.join(os.path.dirname(__file__), "templates")
#     INTERFACES = {
#         "em1": ["172.16", "172.21"],
#         "em2": ["172.17", "172.22"],
#         "em3": ["172.18", "172.23"],
#         "em4": ["172.19", "172.24"],
#         "em5": ["172.20", "172.25"],
#     }
# class _ConfigBase:
# class _Config(_ConfigBase):
#     def __init__(self):
#     def load_from_yaml(self, filepath: str = DEFAULT_CONF_PATH):
#     def __getitem__(self, item: str):
#     def API_URL(self):


import calendar
import os
from datetime import datetime, timedelta
from quads.tools.simple_table_generator import generator
from quads.config import Config
#!/usr/bin/python3




def main():
    months_out = 4
    now = datetime.now()
    dates = [now]

    for i in range(months_out):
        previous = dates[i]
        next_date = previous + timedelta(calendar.mdays[(previous.month % 12) + 1])
        dates.append(next_date)

    if not os.path.exists(Config["visual_web_dir"]):
        os.makedirs(Config["visual_web_dir"])

    for _date in dates:
        gen_time = "Allocation Map for %s-%.2d" % (_date.year, _date.month)
        content = generator(
            None, calendar.mdays[_date.month], _date.month, _date.year, gen_time

# Path: quads/tools/simple_table_generator.py
# def generator(_host_file, _days, _month, _year, _gentime):
#     if _host_file:
#         with open(_host_file, "r") as f:
#             reader = csv.reader(f)
#             hosts = list(reader)
#     else:
#         hosts = sorted(Host.objects(retired=False, broken=False), key=lambda x: x.name)
# 
#     lines = []
#     __days = []
#     non_allocated_count = 0
#     all_samples = []
#     all_samples.extend(range(129296, 129510))
#     all_samples.extend(range(128000, 128252))
#     samples = random.sample(all_samples, 100)
#     exclude = [129401, 129484]
#     emojis = [emoji for emoji in samples if emoji not in exclude]
#     colors = [random_color() for _ in range(100)]
#     colors[0] = "#A9A9A9"
#     for i, host in enumerate(hosts):
#         line = {"hostname": host.name}
#         __days = []
#         for j in range(1, _days + 1):
#             cell_date = "%s-%.2d-%.2d 01:00" % (_year, _month, j)
#             cell_time = datetime.strptime(cell_date, "%Y-%m-%d %H:%M")
#             schedule = Schedule.current_schedule(host=host, date=cell_time).first()
#             if schedule:
#                 chosen_color = schedule.cloud.name[5:]
#             else:
#                 non_allocated_count += 1
#                 chosen_color = "01"
#             _day = {
#                 "day": j,
#                 "chosen_color": chosen_color,
#                 "emoji": "&#%s;" % emojis[int(chosen_color) - 1],
#                 "color": colors[int(chosen_color) - 1],
#                 "cell_date": cell_date,
#                 "cell_time": cell_time,
#             }
# 
#             if schedule:
#                 cloud = (
#                     CloudHistory.objects(
#                         __raw__={
#                             "_id": {"$lt": schedule.id},
#                             "name": schedule.cloud.name,
#                         }
#                     )
#                     .order_by("-_id")
#                     .first()
#                 )
#                 _day["display_description"] = cloud.description
#                 _day["display_owner"] = cloud.owner
#                 _day["display_ticket"] = cloud.ticket
#             __days.append(_day)
# 
#         line["days"] = __days
#         lines.append(line)
# 
#     total_hosts = len(hosts)
#     total_use = Schedule.current_schedule().count()
#     utilization = 100 - (non_allocated_count * 100 // (_days * total_hosts))
#     utilization_daily = total_use * 100 // total_hosts
#     with open(os.path.join(Config.TEMPLATES_PATH, "simple_table_emoji")) as _file:
#         template = Template(_file.read())
#     content = template.render(
#         gentime=_gentime,
#         _days=_days,
#         lines=lines,
#         utilization=utilization,
#         utilization_daily=utilization_daily,
#         total_use=total_use,
#         total_hosts=total_hosts,
#     )
# 
#     return content
# 
# Path: quads/config.py
# DEFAULT_CONF_PATH = os.path.join(os.path.dirname(__file__), "../conf/quads.yml")
#     LOGFMT = "%(asctime)-12s : %(levelname)-8s - %(message)s"
#     STDFMT = "- %(levelname)-8s - %(message)s"
#     API = "v2"
#     FPING_TIMEOUT = 10000
#     QUADSVERSION = "1.1.6"
#     QUADSCODENAME = "gaúcho"
#     SUPPORTED = [
#         "fc640",
#         "r620",
#         "r630",
#         "r640",
#         "640",
#         "r650",
#         "650",
#         "r720",
#         "r730xd",
#         "r930",
#         "r730",
#         "r740xd",
#         "740xd",
#         "r750xd",
#         "r750",
#         "750",
#         "r720xd",
#         "7425",
#         "7525",
#     ]
#     OFFSETS = {"em1": 0, "em2": 1, "em3": 2, "em4": 3, "em5": 4}
#     TEMPLATES_PATH = os.path.join(os.path.dirname(__file__), "templates")
#     INTERFACES = {
#         "em1": ["172.16", "172.21"],
#         "em2": ["172.17", "172.22"],
#         "em3": ["172.18", "172.23"],
#         "em4": ["172.19", "172.24"],
#         "em5": ["172.20", "172.25"],
#     }
# class _ConfigBase:
# class _Config(_ConfigBase):
#     def __init__(self):
#     def load_from_yaml(self, filepath: str = DEFAULT_CONF_PATH):
#     def __getitem__(self, item: str):
#     def API_URL(self):


# Path: quads/tools/simple_table_web.py
import calendar
import os
from datetime import datetime, timedelta
from quads.tools.simple_table_generator import generator
from quads.config import Config

#!/usr/bin/python3




def main():
    months_out = 4
    now = datetime.now()
    dates = [now]

    for i in range(months_out):
        previous = dates[i]
        next_date = previous + timedelta(calendar.mdays[(previous.month % 12) + 1])
        dates.append(next_date)

    if not os.path.exists(Config["visual_web_dir"]):
        os.makedirs(Config["visual_web_dir"])

    for _date in dates:
        gen_time = "Allocation Map for %s-%.2d" % (_date.year, _date.month)
        content = generator(
            None, calendar.mdays[_date.month], _date.month, _date.year, gen_time

        )