Baby Language Lab Scripts
A collection of data processing tools.
 All Classes Namespaces Files Functions Variables Pages
pitch_study_props.py
Go to the documentation of this file.
1 from data_structs.base_objects import DBObject
2 from utils.enum import Enum
3 
5  PROPS = Enum(
6  ['CLIPS_DB_PATH', 'CLIPS_DIR_PATH', 'MAX_PARTS_PER_BATCH', 'NUM_OPTIONS', 'BREAK_INTERVAL', 'INTER_CLIP_SOUND_DEL'],
7  ['clips_db_path', 'clips_dir_path', 'max_parts_per_batch', 'num_options', 'break_interval', 'inter_clip_sound_del']
8  )
9 
10  def __init__(
11  self,
12  clips_db_path,
13  clips_dir_path,
14  max_parts_per_batch,
15  num_options,
16  break_interval,
17  inter_clip_sound_del,
18  db_id = None
19  ):
20  super(PitchStudyProps, self).__init__()
21 
22  self.clips_db_path = clips_db_path
23  self.clips_dir_path = clips_dir_path
24  self.max_parts_per_batch = max_parts_per_batch
25  self.num_options = num_options
26  self.break_interval = break_interval
27  self.inter_clip_sound_del = inter_clip_sound_del
28  self.db_id = db_id
29 
30  @staticmethod
31  def db_select(db, ids=[]):
32  DBObject.db_select(db, ids)
33 
34  where_cond = None
35  if ids:
36  where_cond = DBObject._build_where_cond_from_ids(ids)
37 
38  rows = db.select(
39  'pitch_study_props',
40  'clips_db_path clips_dir_path max_parts_per_batch num_options break_interval inter_clip_sound_del id'.split(),
41  where_cond=where_cond
42  )
43 
44  props = []
45  for cur_row in rows:
46  props.append(PitchStudyProps(*cur_row))
47  return props
48 
49  def db_delete(self, db):
50  super(PitchStudyProps, self).db_delete(db)
51 
52  num_rows = db.delete('pitch_study_props', 'id = ?', [self.db_id])
53  self.db_id = None
54 
55  return num_rows
56 
57  #prop must be a value from the PitchStudyApp.PROPS enum
58  def update_prop(self, db, prop, val):
59  rowcount = db.update(
60  'pitch_study_props',
61  [prop], #I know...it's not right - but there is no risk of SQL injection in the lab
62  where_cond='id = ?',
63  params=[val, self.db_id]
64  )
65 
66  if rowcount > 0:
67  setattr(self, prop, val)