| 135 | } |
| 136 | |
| 137 | pub(crate) fn create_row( |
| 138 | convert_datetime: bool, |
| 139 | explode: bool, |
| 140 | column_names: &Vec<String>, |
| 141 | properties_map: HashMap<String, Prop>, |
| 142 | prop_time_dict: HashMap<i64, HashMap<String, Prop>>, |
| 143 | row_header: Vec<Prop>, |
| 144 | start_point: usize, |
| 145 | history: Vec<i64>, |
| 146 | ) -> Vec<Vec<Prop>> { |
| 147 | if explode { |
| 148 | let new_rows: Vec<Vec<Prop>> = prop_time_dict |
| 149 | .par_iter() |
| 150 | .map(|(time, item_dict)| { |
| 151 | let mut row: Vec<Prop> = row_header.clone(); |
| 152 | for prop_name in &column_names[start_point..(column_names.len() - 1)] { |
| 153 | if let Some(prop_val) = properties_map.get(prop_name) { |
| 154 | row.push(prop_val.clone()); |
| 155 | } else if let Some(prop_val) = item_dict.get(prop_name) { |
| 156 | row.push(prop_val.clone()); |
| 157 | } else { |
| 158 | row.push(Prop::from("")); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | if convert_datetime { |
| 163 | row.push(Prop::DTime(time.dt().unwrap())); |
| 164 | } else { |
| 165 | row.push(Prop::from(*time)); |
| 166 | } |
| 167 | |
| 168 | row |
| 169 | }) |
| 170 | .collect(); |
| 171 | new_rows |
| 172 | } else { |
| 173 | let mut row: Vec<Prop> = row_header.clone(); |
| 174 | // Flatten properties into the row |
| 175 | for prop_name in &column_names[start_point..(column_names.len() - 1)] { |
| 176 | // Skip the first column (name) |
| 177 | let blank_prop = Prop::from(""); |
| 178 | let prop_value = properties_map.get(prop_name).unwrap_or(&blank_prop); |
| 179 | row.push(prop_value.clone()); // Append property value as string |
| 180 | } |
| 181 | |
| 182 | if convert_datetime { |
| 183 | let update_list = history |
| 184 | .iter() |
| 185 | .map(|val| Prop::DTime(val.dt().unwrap())) |
| 186 | .collect_vec(); |
| 187 | row.push(Prop::from(update_list)); |
| 188 | } else { |
| 189 | let update_list = Prop::from(history.iter().map(|&val| Prop::from(val)).collect_vec()); |
| 190 | row.push(update_list); |
| 191 | } |
| 192 | vec![row] |
| 193 | } |
| 194 | } |