private IEnumerator LoadData()
    {
        var filename = Paths.Data + path + Path.DirectorySeparatorChar + siteBrowser.ActiveSite.Name + ".csv";

#if !UNITY_WEBGL
        if (File.Exists(filename))
#endif
        {
            municipalBudgetOutput.ShowMessage("Loading budget data for " + siteBrowser.ActiveSite.Name);

            yield return(MunicipalityIO.Load(filename, (d) => data = d, OnNoData));

            if (data != null)
            {
                if (!budgetLayer.IsVisible())
                {
                    ShowBudgetLayer(true);
                }

                budgetLayer.UpdateGrid(data.north, data.east, data.south, data.west, data.countX, data.countY);
                budgetLayer.UpdateData();
                UpdateOutput();
                UpdateHighlightGrid();
                EnableSliders(true);
            }
        }
#if !UNITY_WEBGL
        else
        {
            OnNoData();
        }
#endif

        loadDataCR = null;
    }
    private void OnNoData()
    {
        if (budgetLayer.IsVisible())
        {
            ShowBudgetLayer(false);
        }

        data = null;
        budgetLayer.ResetGrid();
        UpdateOutput();
    }
    private void OnBeforeActiveSiteChange(Site nextSite, Site previousSite)
    {
        if (loadDataCR != null)
        {
            StopCoroutine(loadDataCR);
        }

        data = null;
        highlightLayer.Grid.values = null;

        EnableSliders(false);
    }
Ejemplo n.º 4
0
    //+ This guy is the bottleneck (+100ms). Try to optimize
    public void Update(float[] values, byte[] masks, float[] divisors, MunicipalityData data)
    {
        // Add all cells to list based on municipality
        for (int i = 0; i < values.Length; ++i)
        {
            if (data.ids[i] < 0)
            {
                continue;
            }

            var id = data.ids[i];
            if (!idToValueList.ContainsKey(id))
            {
                idToValueList.Add(id, values[i]);
                idToMaskList.Add(id, masks[i]);
                idToDivisors.Add(id, divisors[i]);
            }
            else
            {
                idToValueList[id] += values[i];
                idToMaskList[id]  &= masks[i];
                idToDivisors[id]  += divisors[i];
            }
        }

        // Translate BudgetData to budget Items
        summary = 0;
        int        index = 0;
        int        count = BudgetItems.Count;
        BudgetItem budgetItem;

        foreach (var pair in idToValueList)
        {
            float totalValue = pair.Value / idToDivisors[pair.Key];
            var   name       = data.idToName[pair.Key];
            if (index < count)
            {
                budgetItem       = BudgetItems[index];
                budgetItem.name  = name;
                budgetItem.value = totalValue;
            }
            else
            {
                budgetItem = new BudgetItem {
                    name = name, value = totalValue
                };
                BudgetItems.Add(budgetItem);
                count++;
            }
            budgetItem.isMasked = idToMaskList[pair.Key] == 0;
            summary            += totalValue;
            index++;
        }

        // Remove remaining items
        if (idToValueList.Count < count)
        {
            BudgetItems.RemoveRange(idToValueList.Count, count - idToValueList.Count);
        }

        idToValueList.Clear();
        idToMaskList.Clear();
        idToDivisors.Clear();
    }
Ejemplo n.º 5
0
 public BudgetData(float[] values, byte[] masks, float[] divisors, MunicipalityData data)
 {
     Update(values, masks, divisors, data);
 }