| 119 | } |
| 120 | |
| 121 | void ChargeSocketsHelper::AggregateChargeSocketKey(std::string const & k, std::string const & v) |
| 122 | { |
| 123 | auto keys = strings::Tokenize(k, ":"); |
| 124 | ASSERT(keys[0] == "socket", ()); // key must start with "socket:" |
| 125 | if (keys.size() < 2 || keys.size() > 3) |
| 126 | { |
| 127 | LOG(LWARNING, ("Invalid socket key:", k)); |
| 128 | return; |
| 129 | } |
| 130 | |
| 131 | std::string type(keys[1]); |
| 132 | |
| 133 | bool isOutput = false; |
| 134 | if (keys.size() == 3) |
| 135 | { |
| 136 | if (keys[2] == "output") |
| 137 | isOutput = true; |
| 138 | else |
| 139 | return; // ignore other suffixes |
| 140 | } |
| 141 | |
| 142 | // normalize type |
| 143 | static ankerl::unordered_dense::map<std::string_view, std::string_view> const kTypeMap = { |
| 144 | {"tesla_supercharger", "nacs"}, |
| 145 | {"tesla_destination", "nacs"}, |
| 146 | {"tesla_standard", "nacs"}, |
| 147 | {"tesla", "nacs"}, |
| 148 | {"tesla_supercharger_ccs", "type2_combo"}, |
| 149 | {"ccs", "type2_combo"}, |
| 150 | {"type1_cable", "type1"}, |
| 151 | }; |
| 152 | |
| 153 | auto itMap = kTypeMap.find(type); |
| 154 | if (itMap != kTypeMap.end()) |
| 155 | type = itMap->second; |
| 156 | |
| 157 | if (std::find(SUPPORTED_TYPES.begin(), SUPPORTED_TYPES.end(), type) == SUPPORTED_TYPES.end()) |
| 158 | type = UNKNOWN; |
| 159 | |
| 160 | // Tokenize counts or powers |
| 161 | auto tokens = strings::Tokenize(v, ";"); |
| 162 | if (tokens.empty()) |
| 163 | return; |
| 164 | |
| 165 | if (!isOutput) |
| 166 | { |
| 167 | // Parse counts |
| 168 | std::vector<unsigned int> counts; |
| 169 | for (auto & t : tokens) |
| 170 | { |
| 171 | strings::Trim(t); |
| 172 | if (t.empty()) |
| 173 | continue; |
| 174 | |
| 175 | if (t == "yes") |
| 176 | counts.push_back(0); |
| 177 | else |
| 178 | { |