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 102 of file data_formats.py.

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().

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

◆ _objects_to_dicts()

def data_formats._objects_to_dicts (   data)
private

Definition at line 96 of file data_formats.py.

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().

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

◆ _to_array_of_dicts()

def data_formats._to_array_of_dicts (   data)
private

Definition at line 59 of file data_formats.py.

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

Referenced by to_array_of_dicts().

59 def _to_array_of_dicts(data):
60  # check to see if the user has returned a data source, instead of a json data node
61  if not(data.__class__.__name__ in ["json_list", "json_dict", "json_basic"]):
62  data = json_data_node.make(data)
63  headers = data.get("headers").data()
64  data_list = data.get("data").data()
65  def unicode_to_str(string):
66  return str(string) if type(string) == str else string
67  headers = list(map(unicode_to_str, headers))
68  def row_to_dict(row):
69  row = list(map(unicode_to_str, row))
70  return dict(list(zip(headers, row)))
71  array_of_dicts = list(map(row_to_dict, data_list))
72  return json_data_node.make(array_of_dicts)
73 
OutputIterator zip(InputIterator1 first1, InputIterator1 last1, InputIterator2 first2, InputIterator2 last2, OutputIterator result, Compare comp)
def _to_array_of_dicts(data)
Definition: data_formats.py:59
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
#define str(s)

◆ _to_datatables()

def data_formats._to_datatables (   data)
private

Definition at line 74 of file data_formats.py.

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

74 def _to_datatables(data):
75  headers = list(map(str, list(data.get(0).data().keys())))
76  new_data = []
77  for n in range(0, len(data.data())):
78  new_data.append([str(entry) if type(entry) == str else entry for entry in list(data.get(n).data().values())])
79  return json_data_node.make({
80  "headers" : headers,
81  "data" : new_data
82  })
83 
char data[epos_bytes_allocation]
Definition: EPOS_Wrapper.h:80
def _to_datatables(data)
Definition: data_formats.py:74
#define str(s)

◆ apply_function()

def data_formats.apply_function (   data,
  function,
  key 
)

Definition at line 88 of file data_formats.py.

References HiBiasedCentrality_cfi.function, and FastTimerService_cff.range.

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

◆ objects_to_dicts()

def data_formats.objects_to_dicts (   script)

Definition at line 48 of file data_formats.py.

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

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

◆ query()

def data_formats.query (   script)

Definition at line 39 of file data_formats.py.

References submitPVResolutionJobs.script, and str.

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

◆ to_array_of_dicts()

def data_formats.to_array_of_dicts (   script)

Definition at line 17 of file data_formats.py.

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

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

◆ to_datatables()

def data_formats.to_datatables (   script)

Definition at line 28 of file data_formats.py.

References caHitNtupletGeneratorKernels.if(), submitPVResolutionJobs.script, and str.

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

◆ to_sql_query()

def data_formats.to_sql_query (   data)

Definition at line 84 of file data_formats.py.

84 def to_sql_query(data):
85  return data.to_sql()
86 
87 # apply function to specific column of data, assuming data
def to_sql_query(data)
Definition: data_formats.py:84