예제 #1
0
class TestPitch(TestCase):

    ###################################################################
    def setUp(self):
        self.a4 = Pitch('440')

    ###################################################################
    def test_multiply(self):
        self.assertEqual(Pitch('880'), Pitch('440') * 2)

    ###################################################################
    def test_divide(self):
        self.assertEqual(Pitch('440'), Pitch('880') / 2)
        self.assertEqual(Pitch('2'), Decimal('880') / Pitch('440'))

    ###################################################################
    def test_add(self):
        self.assertEqual(Pitch('440'), Pitch('220') + Decimal('220'))

    ###################################################################
    def test_subtract(self):
        self.assertEqual(Pitch('220'), Pitch('440') - Decimal('220'))
        self.assertEqual(Pitch('220'), Decimal('440') - Pitch('220'))

    ###################################################################
    def test_greater_than(self):
        self.assertTrue(Pitch('440') > Pitch('220'))

    ###################################################################
    def test_less_than(self):
        self.assertTrue(Pitch('220') < Pitch('440'))

    ###################################################################
    def test_notes(self):
        self.assertEqual([B_sharp, C, D_double_flat], Pitch('16.35').notes)
        self.assertEqual([G_double_sharp, A, B_double_flat], Pitch('440').notes)

    ####################################################################
    def test_in_tune(self):
        pitch_2 = Pitch('440')
        self.assertTrue(IN_TUNE, self.a4.in_tune(pitch_2))

    ####################################################################
    def test_sharp(self):
        pitch_2 = self.a4 * Decimal('1.051')
        self.assertEqual(SHARP, self.a4.in_tune(pitch_2))

        pitch_2 = self.a4 * Decimal('1.05')
        self.assertEqual('In Tune', self.a4.in_tune(pitch_2))

    ####################################################################
    def test_flat(self):
        pitch_2 = self.a4 * Decimal('0.949')
        self.assertEqual(FLAT, self.a4.in_tune(pitch_2))

        pitch_2 = self.a4 * Decimal('0.95')
        self.assertEqual(IN_TUNE, self.a4.in_tune(pitch_2))
def reg_pitch():

    form = PitchForm(request.form)

    if request.method == 'POST':
        try:
            pitch = Pitch(form.proposal_name.data, form.proposal_outline.data,
                          form.interests.data, form.launch_date.data,
                          form.pitcher_id.data)
            print(pitch.pitcher_id)
            print(pitch.launch_date)
            db_session.add(pitch)
            db_session.commit()

        # catch duplicate entries
        except IntegrityError:
            db_session.rollback()

            flash("This pitch name is already registered with pitchCatch!")
            return render_template('reg_pitch.html', form=form)

        proposal_name = pitch.proposal_name
        flash("Your pitch is registered with pitchCatch!")
        return redirect(url_for('pitch_profile', proposal_name=proposal_name))

    sponsor = db_session.query(Pitcher).all()
    return render_template('reg_pitch.html', form=form, sponsor=sponsor)
예제 #3
0
def addPitch():

    if 'email' not in session:
        return redirect(url_for('signin'))

    user = Smarketer.query.filter_by(username=session['email']).first()

    if user is None:
        return redirect(url_for('signin'))
    else:
        form = PitchForm()

        if request.method == 'POST':
            if form.validate() == False:
                return render_template('addPitch.html', form=form)
            else:
                newPitch = Pitch(form.subject.data, form.message.data,
                                 form.pitchTitle.data)
                db.session.add(newPitch)
                db.session.commit()

                form.subject.data = ""
                form.message.data = ""
                form.pitchTitle.data = ""
                return render_template('addPitch.html',
                                       form=form,
                                       success=True)

        elif request.method == 'GET':
            return render_template('addPitch.html', form=form)
예제 #4
0
def pitch():

    pitch = Pitch()
    input_data = request.get_json(force=True)
    if not isinstance(input_data, dict):
        return jsonify(status='failure', error='Request data must be a JSON Object', errors=[]), 400


    # validate json user input using WTForms-JSON
    form = PitchForm.from_json(input_data)
    if not form.validate():
        return jsonify(errors=form.errors, status='failure', error='Invalid data'), 400

    # update user in database
    pitch.set_columns(**form.patch_data)
    db.session.add(pitch)
    db.session.commit()

    return jsonify({'status':'success'})
예제 #5
0
 def parse_pitches(self):
     # Parse every pitch in all innings, adding them to the to_load list.
     pitch_counter = count()
     for pitch in self.innings.find_all('pitch'):
         # Some years are missing pitch_ids. Since we're using it as a key,
         # assign here and increment the counter
         p = {}
         p['game_id'] = self.game_id
         p['pitch_id'] = int(pitch.get('id', next(pitch_counter)))
         p['at_bat_number'] = try_int(pitch.parent.get('num'))
         p['description'] = pitch.get('des')
         p['type'] = pitch.get('type')
         try:
             t = dateutil.parser.parse(pitch.get('tfs_zulu', ''))
             p['timestamp'] = t.astimezone(timezone('America/New_York'))
         except ValueError:
             logging.warning(
                 'Could not parse timestamp: Game {}; pitch {}'.format(
                     self.game_id, p['pitch_id']))
         p['x'] = try_float(pitch.get('x'))
         p['y'] = try_float(pitch.get('y'))
         p['event_num'] = try_int(pitch.get('event_num'))
         p['sv_id'] = pitch.get('sv_id')
         p['play_guid'] = pitch.get('play_guid')
         p['start_speed'] = try_float(pitch.get('start_speed'))
         p['end_speed'] = try_float(pitch.get('end_speed'))
         p['sz_top'] = try_float(pitch.get('sz_top'))
         p['sz_bottom'] = try_float(pitch.get('sz_bot'))
         p['pfx_x'] = try_float(pitch.get('pfx_x'))
         p['pfx_z'] = try_float(pitch.get('pfx_z'))
         p['x0'] = try_float(pitch.get('x0'))
         p['y0'] = try_float(pitch.get('y0'))
         p['z0'] = try_float(pitch.get('z0'))
         p['vx0'] = try_float(pitch.get('vx0'))
         p['vy0'] = try_float(pitch.get('vy0'))
         p['vz0'] = try_float(pitch.get('vz0'))
         p['ax'] = try_float(pitch.get('ax'))
         p['ay'] = try_float(pitch.get('ay'))
         p['az'] = try_float(pitch.get('az'))
         p['break_y'] = try_float(pitch.get('break_y'))
         p['break_angle'] = try_float(pitch.get('break_angle'))
         p['break_length'] = try_float(pitch.get('break_length'))
         p['pitch_type'] = pitch.get('pitch_type')
         p['type_confidence'] = try_float(pitch.get('type_confidence'))
         p['zone'] = try_int(pitch.get('zone'))
         p['nasty'] = try_int(pitch.get('nasty'))
         p['spin_dir'] = try_float(pitch.get('spin_dir'))
         p['spin_rate'] = try_float(pitch.get('spin_rate'))
         # Drop None items and add Pitch to to_load
         p = dict((k, v) for k, v in p.items() if v is not None)
         logging.info(p)
         self.to_load.append(Pitch(**p))
예제 #6
0
def parse_inning(request, url, date):
    try:
        root = ET.fromstring(request.text)
        at_bats = [[e for e in side if e.tag == 'atbat'] for side in root]
    except ET.ParseError:
        logger.error("XML parsing error on %s", url)
        return

    for at_bat in sum(at_bats, []):
        pitches = [x for x in at_bat if x.tag == 'pitch']
        pitcher = int(at_bat.attrib['pitcher'])
        hitter = int(at_bat.attrib['batter'])
        stand = at_bat.attrib['stand']
        for pitch in pitches:
            pitch = pitch.attrib
            for key, value in pitch.items():
                if value == "placeholder":
                    pitch[key] = 0
            try:
                new_pitch = Pitch(pitcher=pitcher,
                                  hitter=hitter,
                                  date=date,
                                  stand=stand,
                                  outcome=pitch['des'],
                                  start_speed=float(pitch['start_speed']),
                                  end_speed=float(pitch['end_speed']),
                                  sz_top=float(pitch['sz_top']),
                                  sz_bot=float(pitch['sz_bot']),
                                  pfx_x=float(pitch['pfx_x']),
                                  pfx_z=float(pitch['pfx_z']),
                                  px=float(pitch['px']),
                                  pz=float(pitch['pz']),
                                  x0=float(pitch['x0']),
                                  z0=float(pitch['z0']),
                                  pitch_type=pitch['pitch_type'],
                                  zone=int(pitch['zone']),
                                  spin_dir=float(pitch['spin_dir']),
                                  spin_rate=float(pitch['spin_rate']))
                session.add(new_pitch)
                session.commit()
            except KeyError:
                logger.error("Key Missing For %s", url, exc_info=True)
                continue
예제 #7
0
 def test_subtract(self):
     self.assertEqual(Pitch('220'), Pitch('440') - Decimal('220'))
     self.assertEqual(Pitch('220'), Decimal('440') - Pitch('220'))
예제 #8
0
 def test_in_tune(self):
     pitch_2 = Pitch('440')
     self.assertTrue(IN_TUNE, self.a4.in_tune(pitch_2))
예제 #9
0
 def test_less_than(self):
     self.assertTrue(Pitch('220') < Pitch('440'))
예제 #10
0
 def test_notes(self):
     self.assertEqual([B_sharp, C, D_double_flat], Pitch('16.35').notes)
     self.assertEqual([G_double_sharp, A, B_double_flat], Pitch('440').notes)
예제 #11
0
 def setUp(self):
     self.user_Moringa = User(username = '******',password = '******', email = '*****@*****.**')
     self.new_pitch = Pitch(id=1,pitch_title='Test',pitch_content='This is a test pitch',category="interview",user = self.user_Moringa,likes=0,dislikes=0)
     self.new_comment = Comment(id=1,comment='Test comment',user=self.user_Moringa,pitch=self.new_pitch)
예제 #12
0
 def test_greater_than(self):
     self.assertTrue(Pitch('440') > Pitch('220'))
예제 #13
0
 def test_add(self):
     self.assertEqual(Pitch('440'), Pitch('220') + Decimal('220'))
예제 #14
0
 def test_divide(self):
     self.assertEqual(Pitch('440'), Pitch('880') / 2)
     self.assertEqual(Pitch('2'), Decimal('880') / Pitch('440'))
예제 #15
0
 def test_multiply(self):
     self.assertEqual(Pitch('880'), Pitch('440') * 2)
예제 #16
0
 def setUp(self):
     self.a4 = Pitch('440')
예제 #17
0
 def setUp(self):
     """
 Set up method that will run before every Test
 """
     self.new_pitch = Pitch(1234, 'Interview', 'I love interviews', 'Mary',
                            12 / 2 / 2019)