You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

132 lines
4.6 KiB
Python

import click
from flask import Blueprint
from app.factory import db
cli_bp = Blueprint('cli', 'cli', cli_group=None)
@cli_bp.cli.command('init')
def init():
import app.models
db.create_all()
@cli_bp.cli.command('delete_events')
def delete_events():
from app.models import WorkEvent
w = WorkEvent.query.all()
for i in w:
print('Deleting', i.id)
db.session.delete(i)
db.session.commit()
@cli_bp.cli.command('populate_dev_data')
def populate_dev_data():
import arrow
import namegenerator
from app.models import WorkEvent
from random import randrange, choice
from datetime import datetime, timedelta
options = {
'types': ['intro_call', 'saod_call', 'scoping_call', 'proposal_work', 'proposal_call'],
'sas': ['gary', 'dave', 'mark', 'jd'],
'channels': [namegenerator.gen() for i in range(100)]
}
for cx in options['channels']:
sa = choice(options['sas'])
channel = cx
sc_months = randrange(1, 6)
sc_weeks = sc_months * 4
if sc_months > 2:
scoping_calls = randrange(2, 4)
else:
scoping_calls = randrange(1, 3)
saods = 1
proposal_work = randrange(1, 3)
proposal_call = 1
internal_work = randrange(1, 8)
start_hour = randrange(6, 18)
start_min = randrange(1, 60)
start_month = randrange(1, 8)
start_day = randrange(1, 28)
start_date = datetime(2021, start_month, start_day, start_hour, start_min)
saod = WorkEvent(
create_date=datetime(2021, start_month, start_day, start_hour + 1, start_min),
slack_channel=channel,
work_type='saod_call',
start_date=start_date,
end_date=datetime(2021, start_month, start_day, start_hour + 1, start_min),
user=sa,
)
db.session.add(saod)
db.session.commit()
for i in range(scoping_calls):
new_start = start_date + timedelta(days=7*i)
sc = WorkEvent(
create_date=new_start + timedelta(hours=1),
slack_channel=channel,
work_type='scoping_call',
start_date=new_start,
end_date=new_start + timedelta(hours=1),
user=sa,
)
db.session.add(sc)
db.session.commit()
for i in range(proposal_work):
pw_start = start_date + timedelta(days=((7 * scoping_calls) + (3 * i)))
pw = WorkEvent(
create_date=pw_start + timedelta(hours=1),
slack_channel=channel,
work_type='proposal_work',
start_date=pw_start,
end_date=pw_start + timedelta(hours=1),
user=sa,
)
db.session.add(pw)
db.session.commit()
pc_date = start_date + timedelta(days=(7 * scoping_calls) + (3 * proposal_work) + 5)
pc = WorkEvent(
create_date=pc_date + timedelta(hours=1),
slack_channel=channel,
work_type='proposal_call',
start_date=pc_date,
end_date=pc_date + timedelta(hours=1),
user=sa,
)
db.session.add(pc)
db.session.commit()
# for sa in options['sas']:
# for month in range(1, 12):
# for day in range(1, 28):
# for i in range(0, randrange(0, 5)):
# if i == 5:
# break
# # random number of events per day
# hour = randrange(6, 18)
# min = randrange(1, 60)
# start_date = datetime(2021, month, day, hour, min)
# end_date = datetime(2021, month, day, hour + 1, min)
# channel = choice(options['channels'])
# if start_date.strftime("%A") in ['Saturday', 'Sunday']:
# break
# if channel == 'sa-team':
# work_type = 'internal'
# else:
# work_type = choice(options['types'])
# w = WorkEvent(
# create_date=end_date,
# slack_channel=channel,
# work_type=work_type,
# start_date=start_date,
# end_date=end_date,
# user=sa,
# )
# db.session.add(w)
# db.session.commit()
# print(f'Added work event {w.id} for {sa} ({work_type}) on {start_date}')