Skip to content
This repository has been archived by the owner on Jan 5, 2019. It is now read-only.

Commit

Permalink
Wow git is confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
logoman04 committed Oct 15, 2015
1 parent 704cc75 commit cab3f88
Show file tree
Hide file tree
Showing 11 changed files with 401 additions and 706 deletions.
7 changes: 0 additions & 7 deletions Scripts/LoginScripts/EnterLoginCredentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,6 @@ public void AttemptLogin()
LoginManager.loginManager.StartCoroutine("LoginAttempt", creds);
}

public void GuestLogin()
{
//Login as Guest
DataManager.dataManager.isGuest = true;
LoginManager.loginManager.StartCoroutine ("LoginGuest");
}

public void InputEdit()
{
if (emailInput.text.Length > 0 && passwordInput.text.Length > 0)
Expand Down
6 changes: 3 additions & 3 deletions Scripts/Managers/DataManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ public class DataManager : MonoBehaviour {
// Save File variables
public string username, token, ipAddress;
public bool initialLoad = false, stayLoggedIn = false;

//Guest logged in variable
public bool isGuest=false;


// Session stored variables
public RuntimePlatform platform = Application.platform;
Expand Down Expand Up @@ -205,6 +203,8 @@ public IEnumerator PutRequest(object[] parms)
}
yield return null;
}



public void DataDownload(Dictionary<string, string> sensingPoints, int startTime, int endTime, string filePath)
{
Expand Down
11 changes: 1 addition & 10 deletions Scripts/Managers/LoginManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,7 @@ public IEnumerator LoginAttempt(object[] parms)
// Else return to login screen and notify bad of login
yield return null;
}

public IEnumerator LoginGuest()
//Login as Guest.
{
SuccessfulLogin();
//Set Login bool in action buttons as guest.

yield return null;
}


private IEnumerator ValidateToken(string token)
{
yield return null;
Expand Down
70 changes: 28 additions & 42 deletions Scripts/UIScripts/Action Buttons/ActionButtonManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,78 +11,64 @@ public class ActionButtonManager : MonoBehaviour {
public List<Button> actionButtons = new List<Button>();
public Button collapseButton;
public Image collapseArrow;

private bool collapsed = false;
private float panelWidth = 140;

public void Awake(){
// to test if isGuest deactivates.
//isGuest = true;

if (actionButtonManager == null) {
public void Awake()
{
if (actionButtonManager == null)
{
//DontDestroyOnLoad (gameObject);
actionButtonManager = this;
} else if (actionButtonManager != this) {
}
else if (actionButtonManager != this)
{
Destroy (gameObject);
}

if (DataManager.dataManager.isGuest == true) {
foreach (Button button in actionButtons) {
button.interactable = false;
}
}
}

public void SetActionButtonsInteractable(bool val)
{
if (DataManager.dataManager.isGuest == false) {
foreach (Button button in actionButtons) {
button.interactable = val;
}
foreach (Button button in actionButtons)
{
button.interactable = val;
}
}

public void ModuleStart()
{
if (DataManager.dataManager.isGuest == false) {

SetActionButtonsInteractable (false);
}
SetActionButtonsInteractable (false);
}

public void ModuleEnd()
{
if (DataManager.dataManager.isGuest == false) {

SetActionButtonsInteractable (true);
}
SetActionButtonsInteractable (true);
}

public void CollapsePanel(bool val)
{
if (DataManager.dataManager.isGuest == false) {

foreach (Button button in actionButtons) {
button.gameObject.SetActive (!val);
}
foreach (Button button in actionButtons)
{
button.gameObject.SetActive(!val);
}

if (val) {
collapseArrow.transform.rotation = Quaternion.Euler (new Vector3 (0f, 0f, -90f));
transform.GetComponent<RectTransform> ().sizeDelta = new Vector2 (collapseButton.GetComponent<RectTransform> ().rect.width, transform.GetComponent<RectTransform> ().sizeDelta.y);
} else {
collapseArrow.transform.rotation = Quaternion.Euler (new Vector3 (0f, 0f, 90f));
transform.GetComponent<RectTransform> ().sizeDelta = new Vector2 (panelWidth, transform.GetComponent<RectTransform> ().sizeDelta.y);
}
if (val)
{
collapseArrow.transform.rotation = Quaternion.Euler( new Vector3(0f,0f,-90f) );
transform.GetComponent<RectTransform> ().sizeDelta = new Vector2( collapseButton.GetComponent<RectTransform> ().rect.width, transform.GetComponent<RectTransform>().sizeDelta.y);
}
else
{
collapseArrow.transform.rotation = Quaternion.Euler( new Vector3(0f,0f,90f) );
transform.GetComponent<RectTransform> ().sizeDelta = new Vector2( panelWidth, transform.GetComponent<RectTransform>().sizeDelta.y);
}
}

public void CollapseButtonPress()
{
if (DataManager.dataManager.isGuest == false) {

collapsed = !collapsed;
collapsed = !collapsed;

CollapsePanel (collapsed);
}
CollapsePanel (collapsed);
}
}
192 changes: 184 additions & 8 deletions Scripts/UIScripts/Action Buttons/DownloadDataModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,18 @@
using System.Collections.Generic;
using SimpleJSON;

public class DownloadDataModule : MonoBehaviour {
public class DownloadDataModule : MonoBehaviour, ISelectionReceiver<SensingPointChoice> {

public GameObject sensingPointChoicePrefab;
public Transform sensingPointChoiceScrollPanel;
public InputField startDateInput, endDateInput, startTimeInput, endTimeInput;
private string saveFilePath, folderName;
private System.DateTime startTime, endTime;


private List<SensingPointChoice> selectedSensingPoints = new List<SensingPointChoice>();
private Dictionary<SensingPointChoice, Dictionary<string, string>> downloadedData = new Dictionary<SensingPointChoice, Dictionary<string, string>>();


public IEnumerator Initialize()
{
Expand Down Expand Up @@ -51,30 +59,198 @@ public void CreateSensingPointChoice(JSONNode sensingPoint)
}
//Debug.Log (sensingPoint["property"]["name"].Value);
GameObject choice = Instantiate(sensingPointChoicePrefab) as GameObject;
choice.transform.SetParent(sensingPointChoiceScrollPanel, false);

SensingPointChoice script = choice.GetComponent<SensingPointChoice>();
script.selectionReceiver = this;
script.node = sensingPoint;
script.SetName(sensingPoint["property"]["name"].Value);

choice.transform.SetParent(sensingPointChoiceScrollPanel, false);
}

public void CloseButtonPress()
public void MakeSelection(SensingPointChoice choice)
{
EndModule();
if(choice.selected){
selectedSensingPoints.Add(choice);
}
else{
selectedSensingPoints.Remove(choice);
}
}

public void EndModule()
public bool ValidateInputs()
{
ActionButtonManager.actionButtonManager.ModuleEnd ();
Destroy (transform.gameObject);
if(! (selectedSensingPoints.Count > 0))
{
return false;
}
bool isValid1 = System.DateTime.TryParseExact(startDateInput.text,
"MM/dd/yyyy",
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.None,
out startTime);
bool isValid2 = System.DateTime.TryParseExact(endDateInput.text,
"MM/dd/yyyy",
System.Globalization.CultureInfo.InvariantCulture,
System.Globalization.DateTimeStyles.None,
out endTime);

if(!(isValid1 && isValid2))
{
return false;
}
if(!string.IsNullOrEmpty(startTimeInput.text))
{
System.TimeSpan time = System.TimeSpan.Parse(startTimeInput.text);
startTime = startTime.Add(time);
//Debug.Log(startTime);
}
if(!(string.IsNullOrEmpty(endTimeInput.text)))
{
System.TimeSpan time = System.TimeSpan.Parse(endTimeInput.text);
endTime = endTime.Add(time);
}

System.TimeSpan timezoneOffset = System.DateTime.UtcNow - System.DateTime.Now;
startTime = startTime.Add(timezoneOffset);
endTime = endTime.Add(timezoneOffset);

return true;
}

public void DownloadButtonPress()
{
if(ValidateInputs())
{

string defaultFolderName = "GroData from "
+ startTime.ToString("MMM d")
+ " to "
+ endTime.ToString("MMM d");

UniFileBrowser.use.defaultFileName = defaultFolderName;
UniFileBrowser.use.SaveFileWindow (SaveFileFunction);
}
}

public IEnumerator DownloadSequence()
{
foreach(SensingPointChoice choice in selectedSensingPoints)
{
Debug.Log("Getting data...");
yield return StartCoroutine("GetData", choice);
}
foreach(SensingPointChoice sensingPoint in downloadedData.Keys)
{
// Convert to CSV
Debug.Log("Converting to csv string...");
string dataString = FormatDataToCSV(downloadedData[sensingPoint]);
// Write File
Debug.Log("Saving File...");
string fileName = sensingPoint.sensingPointName.text + "_data.csv";
SaveDataFile(dataString, fileName);
}

yield return null;
}

void SaveFileFunction(string path)
{
saveFilePath = path;
Debug.Log (saveFilePath);
// Create folder
System.IO.Directory.CreateDirectory(path);
StartCoroutine("DownloadSequence");
}

IEnumerator GetData(SensingPointChoice choice)
{
System.DateTime epoch = new System.DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);
int startTimeStamp = (int)(startTime-epoch).TotalSeconds;
int endTimeStamp = (int)(endTime-epoch).TotalSeconds;
string spURL = choice.node["url"].Value;
string[] split = spURL.Split(new[] {'/'});
string spID = split[split.Length-2];

string firstURL = DataManager.dataManager.ipAddress
+ "/dataPoint/"
+ "?min_time=" + startTimeStamp.ToString()
+ "&max_time=" + endTimeStamp.ToString()
+ "&sensing_point=" + spID
+ "&limit=1000";

WWW www = new WWW(firstURL);
yield return www;
if(!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);
Debug.Log(www.text);
}
bool next = true;
Dictionary<string, string> sensingPointData = new Dictionary<string, string>();
int pageCount = 1;
int numPoints = 0;

while (next)
{
//Debug.Log("Page number " + pageCount);
JSONNode node = JSON.Parse(www.text);
JSONArray dataPoints = node["results"].AsArray;
foreach(JSONNode point in dataPoints)
{
int time = point["timestamp"].AsInt;
float value = point["value"].AsFloat;//.ToString();
sensingPointData[time.ToString()] = value.ToString();
numPoints+=1;
}
if(node["next"].Value == "null")
{
next = false;
}
else
{
www = new WWW(node["next"].Value);
yield return www;
if(!string.IsNullOrEmpty(www.error))
{
Debug.Log(www.error);
Debug.Log(www.text);
}
pageCount++;
}
}
downloadedData[choice] = sensingPointData;
Debug.Log ("Number of points: " + numPoints);

yield return null;
}

void SaveDataFile(string data, string fileName)
{
string path = saveFilePath + "/" + fileName;
System.IO.File.WriteAllText(path, data);
downloadedData = new Dictionary<SensingPointChoice, Dictionary<string, string>>();
}

private void FormatDataToCSV(string data)
private string FormatDataToCSV(Dictionary<string, string> data)
{
string output = "Time, Value";
foreach(KeyValuePair<string, string> kvp in data)
{
output = output + "\n" + kvp.Key + ", " + kvp.Value;
}

return output;
}
public void CloseButtonPress()
{
EndModule();
}

public void EndModule()
{
ActionButtonManager.actionButtonManager.ModuleEnd ();
Destroy (transform.gameObject);
}

}
2 changes: 1 addition & 1 deletion Scripts/UIScripts/NewPlantTypeModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public IEnumerator CreatePlantType()
form.AddField ("common_name", commonName);
form.AddField ("latin_name", latinName);
form.AddField ("plant_size", "short-leafy");
form.AddField ("model", "http://" + DataManager.dataManager.ipAddress + "/plantModel/1/");
//form.AddField ("model", "http://" + DataManager.dataManager.ipAddress + "/plantModel/1/");
print (DataManager.dataManager.ipAddress);

string url = string.Concat (plantTypeURL, "/");
Expand Down

0 comments on commit cab3f88

Please sign in to comment.