[longomatch] Add players data to csv file



commit 5cfddf5bcc69f7afb5cfb7d928b612b594892c46
Author: Andoni Morales Alastruey <ylatuya gmail com>
Date:   Sun Jan 10 20:17:52 2010 +0100

    Add players data to csv file

 LongoMatch/IO/CSVExport.cs |   96 ++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 84 insertions(+), 12 deletions(-)
---
diff --git a/LongoMatch/IO/CSVExport.cs b/LongoMatch/IO/CSVExport.cs
index 2b0303b..a07123d 100644
--- a/LongoMatch/IO/CSVExport.cs
+++ b/LongoMatch/IO/CSVExport.cs
@@ -47,7 +47,12 @@ namespace LongoMatch.IO
 		#region Public methods
 		public void WriteToFile() {
 			List<List<MediaTimeNode>> list;
-			Dictionary<Tag, List<MediaTimeNode>> dic;
+			Dictionary<Tag, List<MediaTimeNode>> tagsDic;
+			List<Player> localPlayersList;
+			List<Player> visitorPlayersList;
+			Dictionary<Player, List<object[]>> localPlayersDic;
+			Dictionary<Player, List<object[]>> visitorPlayersDic;
+
 			string[] sectionNames;
 			TextWriter tx;
 
@@ -55,10 +60,20 @@ namespace LongoMatch.IO
 			list = project.GetDataArray();
 			sectionNames = project.GetSectionsNames();
 			
-			dic = new Dictionary<Tag, List<MediaTimeNode>>();
-			foreach (Tag tag in project.Tags){
-				dic.Add(tag, new List<MediaTimeNode>());
-			}
+			tagsDic = new Dictionary<Tag, List<MediaTimeNode>>();
+			foreach (Tag tag in project.Tags)
+				tagsDic.Add(tag, new List<MediaTimeNode>());
+			
+			localPlayersList = project.LocalTeamTemplate.GetPlayersList();
+			localPlayersDic = new Dictionary<Player, List<object[]>>();
+			foreach (Player player in localPlayersList)
+				localPlayersDic.Add(player, new List<object[]>());
+			
+			visitorPlayersList =  project.VisitorTeamTemplate.GetPlayersList();
+			visitorPlayersDic = new Dictionary<Player, List<object[]>>();
+			foreach (Player player in visitorPlayersList)
+				visitorPlayersDic.Add(player, new List<object[]>());
+				
 
 			// Write catagories table
 			tx.WriteLine(String.Format("{0};{1};{2};{3};{4};{5}",
@@ -73,7 +88,21 @@ namespace LongoMatch.IO
 				foreach (MediaTimeNode tn in list[i]) {
 					// Parse Play's tags
 					foreach (Tag t in tn.Tags)
-						dic[t].Add(tn);
+						tagsDic[t].Add(tn);
+					
+					// Parse Players data
+					foreach (int playerNumber in tn.LocalPlayers){
+						object[] o = new object[2];
+						o[0] = sectionName;
+						o[1] = tn;
+						localPlayersDic[localPlayersList[playerNumber]].Add(o);
+					}					
+					foreach (int playerNumber in tn.VisitorPlayers){
+						object[] o = new object[2];
+						o[0] = sectionName;
+						o[1] = tn;
+						visitorPlayersDic[visitorPlayersList[playerNumber]].Add(o);
+					}
 					
 					tx.WriteLine("\""+sectionName+"\";\""+
 					             tn.Name+"\";\""+
@@ -86,6 +115,21 @@ namespace LongoMatch.IO
 			tx.WriteLine();
 			tx.WriteLine();			
 			
+			WriteCatagoriesData(tx, tagsDic);
+			
+			// Write local players data
+			WritePlayersData(tx, localPlayersDic);
+			WritePlayersData(tx, visitorPlayersDic);
+			
+			tx.Close();
+			
+			MessagePopup.PopupMessage(null, MessageType.Info, Catalog.GetString("CSV exported successfully."));			
+		}
+		#endregion
+		
+		#region Private Methods
+		
+		private void WriteCatagoriesData(TextWriter tx, Dictionary<Tag, List<MediaTimeNode>> tagsDic){
 			// Write Tags table
 			tx.WriteLine(String.Format("{0};{1};{2};{3};{4};{5}",
 			             Catalog.GetString("Tag"),
@@ -94,9 +138,9 @@ namespace LongoMatch.IO
 			             Catalog.GetString("StartTime"),
 			             Catalog.GetString("StopTime"),
 			             Catalog.GetString("Duration")));
-			foreach (KeyValuePair<Tag,List<MediaTimeNode>> pair in dic){
+			foreach (KeyValuePair<Tag,List<MediaTimeNode>> pair in tagsDic){
 				if (pair.Value.Count == 0)
-					break;				
+					continue;				
 				foreach (MediaTimeNode tn in pair.Value) {
 					tx.WriteLine("\""+pair.Key.Text+"\";\""+
 					             tn.Name+"\";\""+
@@ -105,10 +149,38 @@ namespace LongoMatch.IO
 					             tn.Stop.ToMSecondsString()+"\";\""+
 					             (tn.Stop-tn.Start).ToMSecondsString()+"\"");
 				}				
-			}			
-			tx.Close();
-			
-			MessagePopup.PopupMessage(null, MessageType.Info, Catalog.GetString("CSV exported successfully."));			
+			}
+			tx.WriteLine();
+			tx.WriteLine();			
+		}
+		
+		private void WritePlayersData(TextWriter tx, Dictionary<Player, List<object[]>> playersDic){
+			// Write Tags table
+			tx.WriteLine(String.Format("{0};{1};{2};{3};{4};{5};{6}",
+			                           Catalog.GetString("Player"),
+			                           Catalog.GetString("Category"),
+			                           Catalog.GetString("Name"),
+			                           Catalog.GetString("Team"),
+			                           Catalog.GetString("StartTime"),
+			                           Catalog.GetString("StopTime"),
+			                           Catalog.GetString("Duration")));
+			foreach (KeyValuePair<Player,List<object[]>> pair in playersDic){
+				if (pair.Value.Count == 0)
+					continue;			
+				foreach (object[] o in pair.Value) {
+					string sectionName = (string)o[0];
+					MediaTimeNode tn = (MediaTimeNode)o[1];
+					tx.WriteLine("\""+pair.Key.Name+"\";\""+
+					             sectionName+"\";\""+
+					             tn.Name+"\";\""+
+					             tn.Team+"\";\""+
+					             tn.Start.ToMSecondsString()+"\";\""+
+					             tn.Stop.ToMSecondsString()+"\";\""+
+					             (tn.Stop-tn.Start).ToMSecondsString()+"\"");
+				}				
+			}
+			tx.WriteLine();
+			tx.WriteLine();			
 		}
 		#endregion
 	}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]