// Use this for initialization
	void Start () {

		api = GameObject.Find ("Tileset map").GetComponent<OnlineMaps>();
		e = (Enhet)gameObject.GetComponent<OnlineMapsMarker3DInstance>().marker.customData;
		m = (Måling)e.getSenesteMålingGittDato(Manager.currentDate);
		labelText = e.getEnhetsId ();
		showText = true;

	}
Beispiel #2
0
	public void leggTilMåling (Måling måling)
	{
		målinger.Add (måling);
	}
	void OnGUI(){
		var pointText = Camera.main.WorldToScreenPoint (transform.position);

		GUI.skin = mySkin;
		guiDepth = 1000;
		GUI.depth = guiDepth;
		if (showText) {
			mySkin.label.normal.textColor = Color.black;
			GUI.Label (new Rect (pointText.x - 51, Screen.height - pointText.y + 10, 100, 40), labelText);
			GUI.Label (new Rect (pointText.x - 49, Screen.height - pointText.y + 10, 100, 40), labelText);
			GUI.Label (new Rect (pointText.x - 50, Screen.height - pointText.y + 1 + 10, 100, 40), labelText);
			GUI.Label (new Rect (pointText.x - 50, Screen.height - pointText.y - 1 + 10, 100, 40), labelText);
			
			mySkin.label.normal.textColor = Color.white;
			GUI.Label (new Rect (pointText.x - 50, Screen.height - pointText.y + 10, 100, 40), labelText);
		}


		guiDepth = 0;
		GUI.depth = guiDepth;
		if (showTooltip) {
			m = (Måling)e.getSenesteMålingGittDato(Manager.currentDate);

			mySkin.box.alignment = TextAnchor.MiddleCenter;
			mySkin.box.normal.textColor = Color.white;
			mySkin.box.normal.background = guiDark;

			var barRectNoData = new Rect (point.x, Screen.height - point.y, 180, 20);
			var barRect = new Rect (point.x,Screen.height - point.y, 400, 20);

			Debug.Log (barRect);
			if (barRect.yMin < 0) {
				point.y = Screen.height;
				barRect = new Rect (point.x + Screen.width / 20, point.y, 380, 20);
			}

			Debug.Log (barRect);
			if (barRect.yMin < 0) {
				point.y = Screen.height;
				barRect = new Rect (point.x + Screen.width / 20, point.y, 380, 20);
			}

			var mp = Input.mousePosition;
							
			if (barRect.Contains (new Vector2 (mp.x, Screen.height - mp.y)) && Input.GetMouseButton (0)) {
				moving = true;	
			}
			if (moving && !Input.GetMouseButton (0)) {
				moving = false;
			}
			if (moving) {
			
				if (lastMousePosition != Vector2.zero) {
					var dmp = new Vector2 (mp.x - lastMousePosition.x, mp.y - lastMousePosition.y);

					point = new Vector2(point.x + dmp.x, point.y  + dmp.y);
				}
				lastMousePosition = mp;
			} else {
					lastMousePosition = Vector2.zero;
			}


			if(m != null){
				Dictionary<String, Double> data = m.getKeyValuePairs();

				GUI.Box (barRect, e.getEnhetsId ());

				if(GUI.Button(new Rect (point.x + 398, Screen.height - point.y, 20, 20), xBtn)){
					toggleTooltip();
				}

				mySkin.box.alignment = TextAnchor.UpperLeft;
				mySkin.box.normal.background = guiLight;
				mySkin.box.normal.textColor = Color.black;

				int count = 0;
				foreach (KeyValuePair<String, Double> pair in data)
				{
					mySkin.box.alignment = TextAnchor.UpperLeft;
					mySkin.box.padding.left = 4;
					GUI.Box (new Rect (point.x, Screen.height - point.y + 20 + 11*count, 380, 11), pair.Key.ToString());
					mySkin.box.alignment = TextAnchor.UpperCenter;
					mySkin.box.padding.left = 0;
					GUI.Box (new Rect (point.x + 378, Screen.height - point.y + 20 + 11*count, 40, 11), pair.Value.ToString());
					count++;
				}
			}else{
				GUI.Box (barRectNoData, e.getEnhetsId ());

				if(GUI.Button(new Rect (point.x + 180, Screen.height - point.y , 20, 20), xBtn)){
					toggleTooltip();
				}

				GUI.Box (new Rect (point.x, Screen.height - point.y + 20, 200, 100), "Ingen data tilgjengelig før denne datoen.");
			}
		}
	}
	public List<Lokalitet> readData( string filePath, List<Lokalitet> lokaliteter)
	{
		Dictionary<string, Lokalitet> lokDict = new Dictionary<string, Lokalitet> ();
		List<string> headers = new List<string> ();
		Manager.datatyper = new List<string> ();


		if (lokaliteter != null) {
			foreach (var l in lokaliteter) {
				lokDict.Add (l.getLokalitetsnavn (), l);
			}
		}



		try {
			FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);

			//1. Reading from a binary Excel file ('97-2003 format; *.xls)
			IExcelDataReader excelReader = ExcelReaderFactory.CreateBinaryReader(stream);


			int lokNavnIndex = -1, datoIndex = -1, enhetIndex = -1, antLusTellIndex = -1;


			excelReader.Read();
			if (excelReader.Read()) {
				for (int i = 0; i < excelReader.FieldCount; i++) {

					string h = excelReader.GetString(i);

					//Debug.Log(h);

					if (h != null) {
						headers.Add(h);
						if (h.Equals("Lokalitet")) {
							lokNavnIndex = i;
						} else if (h.Equals("Enhet")){
							enhetIndex = i;
						} else if (h.Equals("Utg?ende Siste dato for lusetelling") || h.Equals ("Utgående Siste dato for lusetelling")) {
							datoIndex = i;
						} else if (h.Equals("Antall lusetellinger i perioden")) {
							antLusTellIndex = i;
						} else if (!h.ToUpper().Contains("DATO")) {
							Manager.datatyper.Add(h);
						}
					}
				}
			}

			if (lokNavnIndex == -1 || enhetIndex == -1 || datoIndex == -1 || antLusTellIndex == -1) {
				Debug.Log ("Lokalitet, Enhet, Dato eller Antall Lusetellinger er ikke med");
				return new List<Lokalitet>();
			}


			while (excelReader.Read())
			{
				try {

					int antLusTell = excelReader.GetInt32(antLusTellIndex);

					if (antLusTell <= 0) {
						continue;
					}


					Lokalitet lok = null;
					string lokNavn;

					// Finn riktig lokalitet
					lokNavn = excelReader.GetString(lokNavnIndex);
					if (lokNavn.ToUpper().Equals("FLERE")) continue;

					if (!lokDict.TryGetValue(lokNavn, out lok)) {


						lok = new Lokalitet();
						lok.setLokalitetsNavn(lokNavn);

						lokDict.Add(lokNavn, lok);

					}


					Enhet enhet;
					string enhetId;

					// Finn riktig enhet

					enhetId = excelReader.GetString(enhetIndex);

					enhet = lok.getEnhetById(enhetId);

					if (enhet == null) {
						enhet = lok.leggTilEnhet(enhetId);
					}






					DateTime dato;
					dato = excelReader.GetDateTime(datoIndex);
					Måling m = new Måling(dato);

					for (int i = 0; i < excelReader.FieldCount; i++) {
						try {

							if (!headers[i].ToUpper().Contains("DATO")) {
								double data = excelReader.GetDouble(i);


								m.AddData(headers[i], data);

								//.Log("Måling lagt til: " + headers[i] + ", " + data);

							}

						} catch (Exception e) {
							//Debug.Log ("Måling ikke lagt til: " + e);
						}

					}
					enhet.leggTilMåling(m);
				} catch (Exception e) {
					Debug.Log(e);
				}
			}

			//6. Free resources (IExcelDataReader is IDisposable)
			excelReader.Close();
			stream.Close();
		} catch (Exception e) {
			Debug.Log (e);
		}

		return new List<Lokalitet>(lokDict.Values);
	}