CMS 3D CMS Logo

Functions
data_formats Namespace Reference

Functions

def _dicts_to_orm_objects (model, data)
 
def _objects_to_dicts (data)
 
def _to_array_of_dicts (data)
 
def _to_datatables (data)
 
def apply_function (data, function, key)
 
def objects_to_dicts (script)
 
def query (script)
 
def to_array_of_dicts (script)
 
def to_datatables (script)
 
def to_sql_query (data)
 

Detailed Description

This file holds decorator functions that can rearrange data returned from data sources.
They should be used to decorate the method that holds the script that is being passed to the framework.

Note: may also contain a decorator that can wrap a class around a function that contains a script (future development).

Function Documentation

◆ _dicts_to_orm_objects()

def data_formats._dicts_to_orm_objects (   model,
  data 
)
private

Definition at line 103 of file data_formats.py.

103 def _dicts_to_orm_objects(model, data):
104  if data.__class__.__name__ in ["json_list", "json_dict", "json_basic"]:
105  data = data.data()
106  new_data = [model(data[n]) for n in range(0, len(data))]
107  return new_data

References ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi.model, and FastTimerService_cff.range.

Referenced by models.generate(), and data_formats_tests.data_formats_tests.test_dicts_to_orm_objects().

◆ _objects_to_dicts()

def data_formats._objects_to_dicts (   data)
private

Definition at line 97 of file data_formats.py.

97 def _objects_to_dicts(data):
98  if data.__class__.__name__ in ["json_list", "json_dict", "json_basic"]:
99  data = data.data()
100  new_data = [data[n].as_dicts() for n in range(0, len(data))]
101  return json_data_node.make(new_data)
102 

References FastTimerService_cff.range.

Referenced by data_sources.json_list.as_table(), objects_to_dicts(), data_formats_tests.data_formats_tests.test_dicts_to_orm_objects(), and data_formats_tests.data_formats_tests.test_orm_objects_to_dicts().

◆ _to_array_of_dicts()

def data_formats._to_array_of_dicts (   data)
private

Definition at line 60 of file data_formats.py.

60 def _to_array_of_dicts(data):
61  # check to see if the user has returned a data source, instead of a json data node
62  if not(data.__class__.__name__ in ["json_list", "json_dict", "json_basic"]):
63  data = json_data_node.make(data)
64  headers = data.get("headers").data()
65  data_list = data.get("data").data()
66  def unicode_to_str(string):
67  return str(string) if isinstance(string, unicode) else string
68  headers = map(unicode_to_str, headers)
69  def row_to_dict(row):
70  row = map(unicode_to_str, row)
71  return dict(zip(headers, row))
72  array_of_dicts = map(row_to_dict, data_list)
73  return json_data_node.make(array_of_dicts)
74 

References data, genParticles_cff.map, str, and ComparisonHelper.zip().

Referenced by to_array_of_dicts().

◆ _to_datatables()

def data_formats._to_datatables (   data)
private

Definition at line 75 of file data_formats.py.

75 def _to_datatables(data):
76  headers = map(str, data.get(0).data().keys())
77  new_data = []
78  for n in range(0, len(data.data())):
79  new_data.append(map(lambda entry : str(entry) if isinstance(entry, unicode) else entry, data.get(n).data().values()))
80  return json_data_node.make({
81  "headers" : headers,
82  "data" : new_data
83  })
84 

References data, relativeConstraints.keys, genParticles_cff.map, FastTimerService_cff.range, str, and contentValuesCheck.values.

◆ apply_function()

def data_formats.apply_function (   data,
  function,
  key 
)

Definition at line 89 of file data_formats.py.

89 def apply_function(data, function, key):
90  data = data.data()
91  def apply_function_to_key(row):
92  row[key] = function(row[key])
93  return row
94  new_data = [apply_function_to_key(data[n]) for n in range(0, len(data))]
95  return json_data_node(new_data)
96 

References HiBiasedCentrality_cfi.function, and FastTimerService_cff.range.

◆ objects_to_dicts()

def data_formats.objects_to_dicts (   script)

Definition at line 49 of file data_formats.py.

49 def objects_to_dicts(script):
50  def new_script(self, connection):
51  try:
52  data = script(self, connection)
53  return _objects_to_dicts(data)
54  except (KeyError, TypeError) as e:
55  raise Exception("The data you gave wasn't in the correct format: %s" % str(e))
56  return new_script
57 
58 # functions used in decorators
59 

References _objects_to_dicts(), submitPVResolutionJobs.script, and str.

◆ query()

def data_formats.query (   script)

Definition at line 40 of file data_formats.py.

40 def query(script):
41  def new_script(self, connection):
42  try:
43  data = script(self, connection)
44  return _to_sql_query(data)
45  except (KeyError, TypeError) as e:
46  raise Exception("The data you gave wasn't in the correct format: %s" % str(e))
47  return new_script
48 

References submitPVResolutionJobs.script, and str.

◆ to_array_of_dicts()

def data_formats.to_array_of_dicts (   script)

Definition at line 18 of file data_formats.py.

18 def to_array_of_dicts(script):
19  def new_script(self, connection):
20  try:
21  data = script(self, connection)
22  array_of_dicts = _to_array_of_dicts(data)
23  return json_data_node.make(array_of_dicts)
24  except (KeyError, TypeError) as e:
25  raise Exception("The data you gave wasn't in the correct format: %s" % str(e))
26  return new_script
27 
28 # convert {{header:value}, ..., {header:value}} to {headers:[], data:[[]]}

References _to_array_of_dicts(), submitPVResolutionJobs.script, and str.

◆ to_datatables()

def data_formats.to_datatables (   script)

Definition at line 29 of file data_formats.py.

29 def to_datatables(script):
30  def new_script(self, connection):
31  try:
32  data = script(self, connection)
33  if(isinstance(data, list)):
34  data = _json_data_node.make(data)
35  return to_datatables(data)
36  except (KeyError, TypeError) as e:
37  raise Exception("The data you gave wasn't in the correct format: %s" % str(e))
38  return new_script
39 

References submitPVResolutionJobs.script, and str.

◆ to_sql_query()

def data_formats.to_sql_query (   data)

Definition at line 85 of file data_formats.py.

85 def to_sql_query(data):
86  return data.to_sql()
87 
88 # apply function to specific column of data, assuming data
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
data_formats._dicts_to_orm_objects
def _dicts_to_orm_objects(model, data)
Definition: data_formats.py:103
relativeConstraints.keys
keys
Definition: relativeConstraints.py:89
submitPVResolutionJobs.script
string script
Definition: submitPVResolutionJobs.py:193
ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi.model
model
Definition: ReggeGribovPartonMC_EposLHC_2760GeV_PbPb_cfi.py:11
data_formats.query
def query(script)
Definition: data_formats.py:40
data_formats.to_array_of_dicts
def to_array_of_dicts(script)
Definition: data_formats.py:18
data_formats.apply_function
def apply_function(data, function, key)
Definition: data_formats.py:89
contentValuesCheck.values
values
Definition: contentValuesCheck.py:38
str
#define str(s)
Definition: TestProcessor.cc:51
data_formats.to_sql_query
def to_sql_query(data)
Definition: data_formats.py:85
data_formats.to_datatables
def to_datatables(script)
Definition: data_formats.py:29
Exception
ComparisonHelper::zip
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
Definition: L1TStage2CaloLayer1.h:41
data_formats._to_datatables
def _to_datatables(data)
Definition: data_formats.py:75
data_formats._to_array_of_dicts
def _to_array_of_dicts(data)
Definition: data_formats.py:60
data_formats._objects_to_dicts
def _objects_to_dicts(data)
Definition: data_formats.py:97
data_formats.objects_to_dicts
def objects_to_dicts(script)
Definition: data_formats.py:49
HiBiasedCentrality_cfi.function
function
Definition: HiBiasedCentrality_cfi.py:4
data
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:79
genParticles_cff.map
map
Definition: genParticles_cff.py:11