public void init(TextAsset csv)
    {
        string[] lines                   = csv.text.Split('\n');
        string[] headersData             = lines[0].Split(',');
        Dictionary <string, int> headers = new Dictionary <string, int>();

        for (int headerIndex = 0; headerIndex < headersData.Length; headerIndex++)
        {
            headers.Add(headersData[headerIndex], headerIndex);
        }

        foreach (string line in lines)
        {
            string[] data = line.Split(',');

            if (data[0] != "Year" && line != string.Empty)
            {
                AmountPerAgeGroup aData = new AmountPerAgeGroup(
                    int.Parse(data[headers["Year"]]),
                    float.Parse(data[headers["age_u19"]]),
                    float.Parse(data[headers["age_20-24"]]),
                    float.Parse(data[headers["age_25-29"]]),
                    float.Parse(data[headers["age_30-34"]]),
                    float.Parse(data[headers["age_35-39"]]),
                    float.Parse(data[headers["age_40u"]])
                    );

                amountsPerAgeGroup.Add(int.Parse(data[headers["Year"]]), aData);
            }
        }
    }
Beispiel #2
0
    //lol this could've been cleaner. F**k it, I'm tired and it works.
    public void setupYear(int year)
    {
        if (spawnCounties.Count == 0)
        {
            foreach (Transform child in this.transform)
            {
                spawnCounties.Add(child.name, child.gameObject);
            }
        }

        AmountPerAgeGroup amount           = dataLoader.GetComponent <DataLoader>().amountPerAgeGroupContainer.GetComponent <AmountPerAgeGroupContainer>().getAmountPerAgeGroupByYear(year);
        PercentPerCounty  percentPerCounty = dataLoader.GetComponent <DataLoader>().percentPerCounty.GetComponent <PercentPerCounty>();

        Dictionary <string, Dictionary <string, int> > amountsPerCounty = new Dictionary <string, Dictionary <string, int> >();
        List <string> allCounties = percentPerCounty.getAllCounties();

        foreach (string county in allCounties)
        {
            Dictionary <string, int> amountsPerAgeGroup = new Dictionary <string, int>();
            amountsPerAgeGroup.Add("amount_u19", Mathf.RoundToInt(percentPerCounty.getPercentForCounty(county) * amount.amount_u19));
            amountsPerAgeGroup.Add("amount_20_24", Mathf.RoundToInt(percentPerCounty.getPercentForCounty(county) * amount.amount_20_24));
            amountsPerAgeGroup.Add("amount_25_29", Mathf.RoundToInt(percentPerCounty.getPercentForCounty(county) * amount.amount_25_29));
            amountsPerAgeGroup.Add("amount_30_34", Mathf.RoundToInt(percentPerCounty.getPercentForCounty(county) * amount.amount_30_34));
            amountsPerAgeGroup.Add("amount_35_39", Mathf.RoundToInt(percentPerCounty.getPercentForCounty(county) * amount.amount_35_39));
            amountsPerAgeGroup.Add("amount_40u", Mathf.RoundToInt(percentPerCounty.getPercentForCounty(county) * amount.amount_40u));
            amountsPerCounty.Add(county, amountsPerAgeGroup);
        }

        foreach (KeyValuePair <string, GameObject> county in spawnCounties)
        {
            List <AgentData> agentsData = new List <AgentData>();
            foreach (KeyValuePair <string, int> rawAgent in amountsPerCounty[county.Key])
            {
                for (int i = 0; i < rawAgent.Value; i++)
                {
                    AgentData newAgent = new AgentData(convertAgeRange(rawAgent.Key), county.Key, selectLeavingDestination(county.Key));
                    agentsData.Add(newAgent);
                }
            }
            Debug.Log("Added " + agentsData.Count + " Agents");

            spawnCounties[county.Key].GetComponent <CountySpawner>().loadYearList(agentsData, logic.GetComponent <Logic>().ticksPerYear);
        }
    }