csvData property

String csvData

VERY FUCKING EXPENSIVE ASS FUNCTION TO CALL LMAOOO

Implementation

String get csvData {
  StringBuffer header = StringBuffer();
  StringBuffer values = StringBuffer();
  // lol nested functions :D
  void writeValue(String prefix, Map<String, dynamic> map) {
    for (MapEntry<String, dynamic> entry in map.entries) {
      header.write(prefix);
      header.write(entry.key);
      header.write(",");
      if (entry.value is List<dynamic>) {
        for (int i = 0;
            i < (entry.value as List<dynamic>).length;
            i++) {
          dynamic curr = (entry.value as List<dynamic>)[i];
          values.write(curr is Enum ? curr.name : curr.toString());
          if (i != (entry.value as List<dynamic>).length - 1) {
            values.write("+");
          }
        }
      } else if (entry.value is Enum) {
        values.write((entry.value as Enum).name);
      } else {
        values.write(entry.value.toString());
      }
      values.write(",");
    }
  }

  Map<String, dynamic> preliminaryMap = preliminary.exportMap();
  preliminaryMap.remove("timestamp");
  writeValue("", preliminaryMap);
  writeValue("A", auto.exportMap());
  writeValue("T", teleop.exportMap());
  writeValue("E", endgame.exportMap());
  writeValue("M", misc.exportMap());
  String headerStr = header.toString();
  String valueStr = values.toString();
  if (headerStr.endsWith(",")) {
    headerStr = headerStr.substring(0, headerStr.length - 1);
  }
  if (valueStr.endsWith(",")) {
    valueStr = valueStr.substring(0, valueStr.length - 1);
  }
  return "$headerStr\n$valueStr";
}