extractModuleStats function

ModuleStatistics? extractModuleStats(
  1. BeautifulSoup soup
)

Implementation

ModuleStatistics? extractModuleStats(BeautifulSoup soup) {
  var table = soup.find('*', id: 's_m_Content_Content_afholdtelektionertbl');
  if (table != null) {
    List<Bs4Element> tRows = table.findAll('tr');
    for (var tRow in tRows) {
      var tdMiddle = tRow.find('b');
      if (tdMiddle != null && tdMiddle.text.contains("Holdet:")) {
        var children = tRow.children.reversed.toList();
        var deviation = extractAbsencePercent(children[0]);
        var normal = int.tryParse(children[1].text);
        var total = int.tryParse(children[2].text);
        var hosted = int.tryParse(tRow.children[1].text);
        if (normal != null && total != null && hosted != null) {
          return ModuleStatistics(
              deviation: deviation,
              total: total,
              normal: normal,
              hosted: hosted);
        }
      }
    }
  }
  return null;
}