예제 #1
0
 def setUp(self):
     self.bean = Bean(id=10, name='testbean', description='test description')
     self.roaster = Roaster(id=20, name='testroaster', description='test description')
     self.roast = Roast(id=30, bean=self.bean, roaster=self.roaster, start_time="7:30:00 PM",
                        start_temp=200, start_weight=200, fc_start_time="7:40:00 PM", fc_start_temp=400,
                        fc_end_time="7:45:00 PM", fc_end_temp=420, sc_start_time="7:47:00 PM",
                        sc_start_temp=430, sc_end_time="7:48:00 PM", sc_end_temp=450, end_time="7:50:00 PM",
                        end_temp=460, end_weight=154, roast_datetime=datetime(2015, 5, 6, 19, 30),
                        notes='test roast notes')
예제 #2
0
def roast_add():
    user = g.user
    form = RoastForm()
    form.bean_id.choices = [(b.id, '%s - %s (%dg)' % (b.purchase_date, b.name, b.weight)) for b in Bean.query.filter_by(
        user_id=user.id).order_by(Bean.purchase_date.desc()).limit(10).all()]
    if form.validate_on_submit():
        _roast = Roast(
            bean_dose=form.bean_dose.data, drop_temp=form.drop_temp.data, dry_end_time=form.dry_end_time.data,
            dry_end_temp=form.dry_end_temp.data, fc_begin_time=form.fc_begin_time.data,
            fc_begin_temp=form.fc_begin_temp.data, fc_end_time=form.fc_end_time.data, fc_end_temp=form.fc_end_temp.data,
            sc_begin_time=form.sc_begin_time.data, sc_begin_temp=form.sc_begin_temp.data,
            sc_end_time=form.sc_end_time.data, sc_end_temp=form.sc_end_temp.data, end_time=form.end_time.data,
            end_temp=form.end_temp.data, end_weight=form.end_weight.data, roaster_machine=form.roaster_machine.data,
            roast_date=form.roast_date.data, notes=form.notes.data, bean_id=form.bean_id.data, user_id=user.id
        )
        Roast.add_roast(_roast)
        return redirect(url_for('roast_list'))
    return render_template('roast_add.html', form=form)
예제 #3
0
def roast_add(roast_id=None):
    user = g.user
    form = RoastForm()
    form.bean_id.choices = [(b.id, '%s - %s (%dg)' % (b.purchase_date, b.name, b.weight)) for b in Bean.query.filter_by(
        user_id=user.id).order_by(Bean.purchase_date.desc()).limit(10).all()]
    if roast_id:
        roast = Roast.query.get(roast_id)
        form.bean_dose.data = Decimal(roast.bean_dose) / 100
        form.drop_temp.data = roast.drop_temp
        form.dry_end_time.data = seconds_to_timestring(roast.dry_end_time)
        form.dry_end_temp.data = roast.dry_end_temp
        form.fc_begin_time.data = seconds_to_timestring(roast.fc_begin_time)
        form.fc_begin_temp.data = roast.fc_begin_temp
        form.fc_end_time.data = seconds_to_timestring(roast.fc_end_time)
        form.fc_end_temp.data = roast.fc_end_temp
        form.sc_begin_time.data = seconds_to_timestring(roast.sc_begin_time)
        form.sc_begin_temp.data = roast.sc_begin_temp
        form.sc_end_time.data = seconds_to_timestring(roast.sc_end_time)
        form.sc_end_temp.data = roast.sc_end_temp
        form.end_time.data = seconds_to_timestring(roast.end_time)
        form.end_temp.data = roast.end_temp
        form.end_weight.data = Decimal(roast.end_weight) / 100
        form.roaster_machine.data = roast.roaster_machine
        form.roast_date.data = roast.roast_date
        form.notes.data = roast.notes
        form.bean_id.data = roast.bean_id
        form.roast_id.data = roast.id
    if form.validate_on_submit():
        form.roast_id.data = int(form.roast_id.data)
        if form.roast_id.data == 0:
            roast = Roast()
        else:
            roast = Roast.query.get(form.roast_id.data)
            if roast.user_id != user.id:
                return redirect(url_for('roast_list'))
        roast.bean_dose = int(form.bean_dose.data * 100)
        roast.drop_temp = form.drop_temp.data
        roast.dry_end_time = timestring_to_seconds(form.dry_end_time.data)
        roast.dry_end_temp = form.dry_end_temp.data
        roast.fc_begin_time = timestring_to_seconds(form.fc_begin_time.data)
        roast.fc_begin_temp = form.fc_begin_temp.data
        roast.fc_end_time = timestring_to_seconds(form.fc_end_time.data)
        roast.fc_end_temp = form.fc_end_temp.data
        roast.sc_begin_time = timestring_to_seconds(form.sc_begin_time.data)
        roast.sc_begin_temp = form.sc_begin_temp.data
        roast.sc_end_time = timestring_to_seconds(form.sc_end_time.data)
        roast.sc_end_temp = form.sc_end_temp.data
        roast.end_time = timestring_to_seconds(form.end_time.data)
        roast.end_temp = form.end_temp.data
        roast.end_weight = int(form.end_weight.data * 100)
        roast.roaster_machine = form.roaster_machine.data
        roast.roast_date = form.roast_date.data
        roast.notes = form.notes.data
        roast.bean_id = form.bean_id.data
        roast.user_id = user.id
        Roast.add_roast(roast)
        return redirect(url_for('roast_list'))
    return render_template('roast_add.html', form=form)
예제 #4
0
def roast_add(roast_id=None):
    user = g.user
    form = RoastForm()
    form.bean_id.choices = [
        (b.id, '%s - %s (%dg)' % (b.purchase_date, b.name, b.weight))
        for b in Bean.query.filter_by(user_id=user.id).order_by(
            Bean.purchase_date.desc()).limit(10).all()
    ]
    if roast_id:
        roast = Roast.query.get(roast_id)
        form.bean_dose.data = Decimal(roast.bean_dose) / 100
        form.drop_temp.data = roast.drop_temp
        form.dry_end_time.data = seconds_to_timestring(roast.dry_end_time)
        form.dry_end_temp.data = roast.dry_end_temp
        form.fc_begin_time.data = seconds_to_timestring(roast.fc_begin_time)
        form.fc_begin_temp.data = roast.fc_begin_temp
        form.fc_end_time.data = seconds_to_timestring(roast.fc_end_time)
        form.fc_end_temp.data = roast.fc_end_temp
        form.sc_begin_time.data = seconds_to_timestring(roast.sc_begin_time)
        form.sc_begin_temp.data = roast.sc_begin_temp
        form.sc_end_time.data = seconds_to_timestring(roast.sc_end_time)
        form.sc_end_temp.data = roast.sc_end_temp
        form.end_time.data = seconds_to_timestring(roast.end_time)
        form.end_temp.data = roast.end_temp
        form.end_weight.data = Decimal(roast.end_weight) / 100
        form.roaster_machine.data = roast.roaster_machine
        form.roast_date.data = roast.roast_date
        form.notes.data = roast.notes
        form.bean_id.data = roast.bean_id
        form.roast_id.data = roast.id
    if form.validate_on_submit():
        form.roast_id.data = int(form.roast_id.data)
        if form.roast_id.data == 0:
            roast = Roast()
        else:
            roast = Roast.query.get(form.roast_id.data)
            if roast.user_id != user.id:
                return redirect(url_for('roast_list'))
        roast.bean_dose = int(form.bean_dose.data * 100)
        roast.drop_temp = form.drop_temp.data
        roast.dry_end_time = timestring_to_seconds(form.dry_end_time.data)
        roast.dry_end_temp = form.dry_end_temp.data
        roast.fc_begin_time = timestring_to_seconds(form.fc_begin_time.data)
        roast.fc_begin_temp = form.fc_begin_temp.data
        roast.fc_end_time = timestring_to_seconds(form.fc_end_time.data)
        roast.fc_end_temp = form.fc_end_temp.data
        roast.sc_begin_time = timestring_to_seconds(form.sc_begin_time.data)
        roast.sc_begin_temp = form.sc_begin_temp.data
        roast.sc_end_time = timestring_to_seconds(form.sc_end_time.data)
        roast.sc_end_temp = form.sc_end_temp.data
        roast.end_time = timestring_to_seconds(form.end_time.data)
        roast.end_temp = form.end_temp.data
        roast.end_weight = int(form.end_weight.data * 100)
        roast.roaster_machine = form.roaster_machine.data
        roast.roast_date = form.roast_date.data
        roast.notes = form.notes.data
        roast.bean_id = form.bean_id.data
        roast.user_id = user.id
        Roast.add_roast(roast)
        return redirect(url_for('roast_list'))
    return render_template('roast_add.html', form=form)
예제 #5
0
class RoastTestCase(unittest.TestCase):

    def setUp(self):
        self.bean = Bean(id=10, name='testbean', description='test description')
        self.roaster = Roaster(id=20, name='testroaster', description='test description')
        self.roast = Roast(id=30, bean=self.bean, roaster=self.roaster, start_time="7:30:00 PM",
                           start_temp=200, start_weight=200, fc_start_time="7:40:00 PM", fc_start_temp=400,
                           fc_end_time="7:45:00 PM", fc_end_temp=420, sc_start_time="7:47:00 PM",
                           sc_start_temp=430, sc_end_time="7:48:00 PM", sc_end_temp=450, end_time="7:50:00 PM",
                           end_temp=460, end_weight=154, roast_datetime=datetime(2015, 5, 6, 19, 30),
                           notes='test roast notes')

    def test_id(self):
        self.assertEqual(self.roast.id, 30)

    def test_bean(self):
        self.assertEqual(self.bean.id, 10)

    def test_roaster(self):
        self.assertEqual(self.roaster.id, 20)

    def test_start_time(self):
        self.assertEqual(self.roast.start_time, "7:30:00 PM")

    def test_start_temp(self):
        self.assertEqual(self.roast.start_temp, 200)

    def test_start_weight(self):
        self.assertEqual(self.roast.start_weight, 200)

    def test_fc_start_time(self):
        self.assertEqual(self.roast.fc_start_time, "7:40:00 PM")

    def test_fc_start_temp(self):
        self.assertEqual(self.roast.fc_start_temp, 400)

    def test_fc_end_time(self):
        self.assertEqual(self.roast.fc_end_time, "7:45:00 PM")

    def test_fc_end_temp(self):
        self.assertEqual(self.roast.fc_end_temp, 420)

    def test_sc_start_time(self):
        self.assertEqual(self.roast.sc_start_time, "7:47:00 PM")

    def test_sc_start_temp(self):
        self.assertEqual(self.roast.sc_start_temp, 430)

    def test_sc_end_time(self):
        self.assertEqual(self.roast.sc_end_time, "7:48:00 PM")

    def test_sc_end_temp(self):
        self.assertEqual(self.roast.sc_end_temp, 450)

    def test_end_time(self):
        self.assertEqual(self.roast.end_time, "7:50:00 PM")

    def test_end_temp(self):
        self.assertEqual(self.roast.end_temp, 460)

    def test_end_weight(self):
        self.assertEqual(self.roast.end_weight, 154)

    def test_roast_datetime(self):
        self.assertEqual(self.roast.roast_datetime, datetime(2015, 5, 6, 19, 30))

    def test_notes(self):
        self.assertEqual(self.roast.notes, 'test roast notes')

    def test_time_elapsed(self):
        self.assertEqual(self.roast.time_elapsed, 1200)

    def test_first_crack_start(self):
        self.assertEqual(self.roast.first_crack_start, 600)

    def test_first_crack_end(self):
        self.assertEqual(self.roast.first_crack_end, 900)

    def test_second_crack_start(self):
        self.assertEqual(self.roast.second_crack_start, 1020)

    def test_second_crack_end(self):
        self.assertEqual(self.roast.second_crack_end, 1080)

    def test_weight_loss(self):
        self.assertEqual(self.roast.weight_loss, 46)

    def test_percent_weight_loss(self):
        self.assertEqual(self.roast.percent_weight_loss, 23.0)

    def test_formatted_datetime(self):
        self.assertEqual(self.roast.formatted_datetime, '05/06/2015 07:30:00 PM')

    def test_unix_datetime(self):
        self.assertEqual(self.roast.unix_datetime, 1430940600.0)

    def test_line_chart_data(self):
        self.assertEqual(self.roast.line_chart_data(), '[{"y": 200, "x": 0, "label": "Start"}, {"y": 400, "x": 600, "label": "First Crack Start"}, {"y": 420, "x": 900, "label": "First Crack End"}, {"y": 430, "x": 1020, "label": "Second Crack Start"}, {"y": 450, "x": 1080, "label": "Second Crack End"}, {"y": 460, "x": 1200, "label": "End"}]')