| from bs4 import BeautifulSoup | from bs4 import BeautifulSoup | ||||
| class DataTable: | class DataTable: | ||||
| def __init__(self): | |||||
| def __init__(self, rdas_obj=None): | |||||
| self.table = {} | self.table = {} | ||||
| self.cols = {} | |||||
| self.rows = {} | |||||
| self._cols = {} | |||||
| self._rows = {} | |||||
| self.col_labels = {} | |||||
| self.row_labels = {} | |||||
| if rdas_obj != None: | |||||
| self.populate(rdas_obj) | |||||
| def populate(self, rdas_obj): | |||||
| # 1. Put values from results:column:options:key into a list. | |||||
| # a. Sort the list on the int value of the key. | |||||
| # b. Place the list into self._cols, using the value as the key and the index as the value. | |||||
| # 2. Do the same thing for the values from results:row:options:key and self._rows. | |||||
| # 3. Using the key-value pairs in self._cols, place results:column:options:title into self.col_labels | |||||
| # with the self._cols VALUE as the key. | |||||
| # a. REMEMBER that missing values are coded "." in keys but "" in cell descriptors! | |||||
| # 4. Do the same thing for results:row:options:title and self._rows. | |||||
| # 5. For each record in results:cells, get a row-column coordinate by associating row_option and column_option | |||||
| # with a key in each of self._rows and self._cols. | |||||
| # a. Insert the value in results:cells:n:column into self.table at that row-column coordinate. | |||||
| pass | |||||
| def generate_table(self): | |||||
| # Return an object containing self.col_labels, self.row_labels, and self.table. | |||||
| # self._cols and self._rows are for internal use and don't need to be produced. | |||||
| o = { | |||||
| "clabels": self.col_labels, | |||||
| "rlabels": self.row_labels, | |||||
| "values": self.table | |||||
| } | |||||
| return o | |||||
| class DataPocket: | class DataPocket: | ||||
| def __init__(self): | def __init__(self): |