Ejemplo n.º 1
0
 def fill_data(self):
     '''
     Fills in dummy content that we will use for testing
     2 members, Peter and Hans.
     2 workgroups, Systems and Besteling.
     Peter is the only member in Systems.
     Both are members in Bestel, with Hans leading that one.
     Bestel has a shift ('do stuff') for Peter.
     '''
     m1 = Member(fname=u'Peter', prefix=u'de', lname='Pan')
     m1.mem_email = '*****@*****.**'
     m1.mem_enc_pwd = md5_crypt.hash('notsecret')
     self.DBSession.add(m1)
     m2 = Member(fname=u'Hans', prefix=u'de', lname='Wit')
     m1.mem_email = '*****@*****.**'
     self.DBSession.add(m2)
     wg1 = Workgroup(name=u'Systems', desc=u'IT stuff')
     self.DBSession.add(wg1)
     wg2 = Workgroup(name=u'Besteling', desc=u'Besteling at wholesale')
     self.DBSession.add(wg2)
     self.DBSession.flush()  # flush now to get member and workgroup IDs
     wg1.members.append(m1)
     wg1.leaders.append(m1)
     wg2.members.append(m1)
     wg2.members.append(m2)
     wg2.leaders.append(m2)
     self.DBSession.flush()
     s = Shift(wg2.id, 'do stuff', 2012, 6, member=m1)
     self.DBSession.add(s)
     self.DBSession.flush()
     # reserved transaction types
     for rt in reserved_ttype_names:
         self.DBSession.add(TransactionType(name=rt))
     self.DBSession.flush()
Ejemplo n.º 2
0
 def add_shift(month=None, year=None):
     ''' add a shift object to session, several times if people > 1 '''
     shift = Shift(wg_id, '', None, None, None, None)
     shift.workgroup = DBSession().query(Workgroup).get(wg_id)
     shift = fill_shift_from_request(shift, self.request)
     shift.validate()
     db_session.add(shift)
     self.added_shifts.append(shift)
     if month:
         shift.month = month
     if year:
         shift.year = year
     if people > 1:
         for _ in range(1, people):
             s = shift.clone()
             s.workgroup = DBSession().query(Workgroup).get(s.wg_id)
             s.validate()
             db_session.add(s)
             self.added_shifts.append(s)
Ejemplo n.º 3
0
def addOldNames():
    m1 = Member(fname=u'Peter', prefix=u'de', lname='Pan')
    m1.mem_email = '*****@*****.**'
    m1.mem_enc_pwd = md5crypt('notsecret', 'notsecret')
    DBSession.add(m1)
    m2 = Member(fname=u'Hans', prefix=u'de', lname='Wit')
    m1.mem_email = '*****@*****.**'
    DBSession.add(m2)
    wg1 = Workgroup(name=u'Systems', desc=u'IT stuff')
    DBSession.add(wg1)
    wg2 = Workgroup(name=u'Besteling', desc=u'Besteling at wholesale')
    DBSession.add(wg2)
    DBSession.flush()  # flush now to get member and workgroup IDs
    wg1.members.append(m1)
    wg1.leaders.append(m1)
    wg2.members.append(m1)
    wg2.members.append(m2)
    wg2.leaders.append(m2)
    DBSession.flush()
    s = Shift(wg2.id, 'do stuff', 2012, 6, member=m1)
    DBSession.add(s)
    DBSession.flush()
Ejemplo n.º 4
0
def fillDBRandomly(seed, workgroups):
    global default_pwd, fakenames
    if seed: random.seed(seed)
    now = datetime.datetime.now()
    mi = month_info(now.date())
    # read in the fakenames
    names = {}
    for l in file(fakenames, 'r'):
        fname, lname = l.strip().split()
        names[fname] = lname
    namelist = sorted(list(names.keys()))
    # 20% of the people are applicants
    members = []
    for l in namelist[int(len(namelist) * 0.2):]:
        m = Applicant(fname=l, lname=names[l])
        m.email = "*****@*****.**" % (l)
        m.household_size = random.randint(1, 5)
        m.telnr = "06" + unicode(random.randint(10000000, 100000000))
        DBSession.add(m)
        # randomly select a number of workgroups m can be a member of
        DBSession.flush()
    # and the rest are members
    for l in namelist[:int(len(namelist) * 0.8)]:
        prefix = random.choice([u"de", u"van", u"voor", u"van den", u"te"])
        m = Member(fname=l, prefix=prefix, lname=names[l])
        m.mem_email = "*****@*****.**" % (l)
        m.mem_enc_pwd = md5crypt(default_pwd, default_pwd)
        m.mem_mobile = "06" + unicode(random.randint(10000000, 100000000))
        m.household_size = random.randint(1, 5)
        m.mem_membership_paid = True
        if random.random() < 0.01:
            m.mem_membership_paid = False
        m.mem_active = True
        if random.random() < 0.05:
            m.mem_active = False
        m.mem_street = random.choice(namelist) + "street"
        m.mem_house = random.randint(1, 200)
        m.mem_postcode = "1000AB"
        m.city = "Amsterdam"
        DBSession.add(m)
        # randomly select a number of workgroups m can be a member of
        for wg in random.sample(workgroups, random.randint(1,
                                                           len(workgroups))):
            wg.members.append(m)
            # randomly select if m is a leader of the workgroup: only 10 % of all members are leaders
            if random.random() < 0.1:
                wg.leaders.append(m)
        members.append(m)
        DBSession.flush()

    months = [(mi.prev_month, mi.prev_year), (now.month, now.year),
              (mi.next_month, mi.next_year)]
    # next step: create 50 new shifts in each wg with random state/description
    for wg in workgroups:
        for i in range(50):
            task = random.choice([
                "clean", "buy", "feed", "fill", "write", "do", "play", "sleep"
            ])
            month = random.choice(months)
            s = Shift(wg.id,
                      task,
                      month[1],
                      month[0],
                      day=random.randint(1, 30))
            s.state = random.choice(shift_states)
            if not s.state == 'open':
                s.member = random.choice(wg.members)
            DBSession.add(s)
        DBSession.flush()
Ejemplo n.º 5
0
def fillDBRandomly(seed, workgroups, existing_members):
    random.seed(seed)
    now = datetime.datetime.now()
    mi = month_info(now.date())
    # read in the fakenames
    names = {}
    for l in open(fakenamesname, 'r').readlines():
        fname, lname = l.strip().split()
        names[fname] = lname
    namelist = sorted(list(names.keys()))
    # 20% of the people are applicants
    members = existing_members
    for l in namelist[int(len(namelist) * 0.2):]:
        m = Applicant(fname=l, lname=names[l])
        m.email = "*****@*****.**" % (l)
        m.household_size = random.randint(1, 5)
        m.telnr = "06" + str(random.randint(10000000, 100000000))
        DBSession.add(m)
        # randomly select a number of workgroups m can be a member of
        DBSession.flush()
    # and the rest are members
    for l in namelist[:int(len(namelist) * 0.8)]:
        prefix = random.choice([u"de", u"van", u"voor", u"van den", u"te"])
        m = Member(fname=l, prefix=prefix, lname=names[l])
        m.mem_email = "*****@*****.**" % (l)
        m.mem_enc_pwd = md5_crypt.hash(default_pwd)
        m.mem_mobile = "06" + str(random.randint(10000000, 100000000))
        m.mem_household_size = random.randint(1, 5)
        m.mem_membership_paid = True
        if random.random() < 0.01:
            m.mem_membership_paid = False
        m.mem_active = True
        if random.random() < 0.05:
            m.mem_active = False
        m.mem_street = random.choice(namelist) + "street"
        m.mem_house = random.randint(1, 200)
        m.mem_postcode = "1000AB"
        m.mem_city = "Amsterdam"
        DBSession.add(m)
        # randomly select a number of workgroups m can be a member of
        for wg in random.sample(workgroups, random.randint(1,
                                                           len(workgroups))):
            wg.members.append(m)
            # randomly select if m is a leader of the workgroup: only 10 % of all members are leaders
            if random.random() < 0.1:
                wg.leaders.append(m)
        members.append(m)
        DBSession.flush()

    months = [(mi.prev_month, mi.prev_year), (now.month, now.year),
              (mi.next_month, mi.next_year)]
    # next step: create 50 new shifts in each wg with random state/description
    for wg in workgroups:
        for i in range(50):
            task = random.choice([
                "clean", "buy", "feed", "fill", "write", "do", "play", "sleep"
            ])
            month = random.choice(months)
            s = Shift(wg.id,
                      task,
                      month[1],
                      month[0],
                      day=random.randint(1, 30))
            s.state = random.choice(shift_states)
            if not s.state == 'open':
                s.member = random.choice(wg.members)
            DBSession.add(s)
        DBSession.flush()

    # Finally: create 20 transactions per member
    ttype = DBSession.query(TransactionType).filter(
        TransactionType.name == 'Order Charge').first()
    orders = DBSession.query(Order).all()
    for m in members:
        for i in range(20):
            month = random.choice(months)
            t = Transaction(ttype_id=ttype.id,
                            amount=random.random() * 150,
                            date=datetime.datetime(month[1], month[0],
                                                   random.randint(1, 28)),
                            mem_id=m.mem_id)
            t.ttype = ttype
            t.member = m
            if ttype.pos_neg == 'neg':
                t.amount *= -1
            if ttype.name == 'Order Charge':
                o = random.choice(orders)
                t.ord_no = o.id
                t.order = o
            t.validate()
            DBSession.add(t)
        DBSession.flush()