refactoring clusterjson

This commit is contained in:
Ivan Hörler 2018-07-23 14:46:41 +02:00
parent 484396086b
commit cff5a09e01
13 changed files with 289 additions and 146 deletions

View File

@ -1 +0,0 @@
<%@ WebService Language="C#" CodeBehind="ClusterService.asmx.cs" Class="EHEC_Server.ClusterService" %>

View File

@ -1,34 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Services;
using System.Web.Script.Serialization;
namespace EHEC_Server
{
/// <summary>
/// Summary description for ClusterService
/// </summary>
[WebService(Namespace = "http://localhost:50200/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class ClusterService : System.Web.Services.WebService
{
[WebMethod]
//[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
public void GetJson(HttpContext context)
{
context.Response.ContentType = "application/json";
ClusterConverter cc = new ClusterConverter();
var json = cc.WriteJson();
JavaScriptSerializer js = new JavaScriptSerializer();
context.Response.Write(js.Serialize(json));
//return new JavaScriptSerializer().Serialize(json);
}
}
}

View File

@ -83,7 +83,6 @@
<Generator>EntityModelCodeGenerator</Generator> <Generator>EntityModelCodeGenerator</Generator>
<LastGenOutput>Model.Designer.cs</LastGenOutput> <LastGenOutput>Model.Designer.cs</LastGenOutput>
</EntityDeploy> </EntityDeploy>
<Content Include="ClusterService.asmx" />
<Content Include="cluster_dependencies\alchemy\alchemy-white.css" /> <Content Include="cluster_dependencies\alchemy\alchemy-white.css" />
<Content Include="cluster_dependencies\alchemy\alchemy.css" /> <Content Include="cluster_dependencies\alchemy\alchemy.css" />
<Content Include="cluster_dependencies\alchemy\alchemy.js" /> <Content Include="cluster_dependencies\alchemy\alchemy.js" />
@ -165,16 +164,15 @@
<Compile Include="cluster.aspx.designer.cs"> <Compile Include="cluster.aspx.designer.cs">
<DependentUpon>cluster.aspx</DependentUpon> <DependentUpon>cluster.aspx</DependentUpon>
</Compile> </Compile>
<Compile Include="ClusterService.asmx.cs">
<DependentUpon>ClusterService.asmx</DependentUpon>
<SubType>Component</SubType>
</Compile>
<Compile Include="cluster_dependencies\ClusterConverter.cs" /> <Compile Include="cluster_dependencies\ClusterConverter.cs" />
<Compile Include="cluster_dependencies\JsonConverter.cs" /> <Compile Include="cluster_dependencies\JsonConverter.cs" />
<Compile Include="cluster_dependencies\JsonModel.cs" /> <Compile Include="cluster_dependencies\JsonModel.cs" />
<Compile Include="cluster_dependencies\Models\Cluster.cs" />
<Compile Include="cluster_dependencies\Models\ClusterOrigin.cs" /> <Compile Include="cluster_dependencies\Models\ClusterOrigin.cs" />
<Compile Include="cluster_dependencies\Models\ClusterPatient.cs" /> <Compile Include="cluster_dependencies\Models\ClusterPatient.cs" />
<Compile Include="cluster_dependencies\Models\ClusterResult.cs" /> <Compile Include="cluster_dependencies\Models\ClusterResult.cs" />
<Compile Include="cluster_dependencies\Models\Edges.cs" />
<Compile Include="cluster_dependencies\Models\Nodes.cs" />
<Compile Include="DatabaseAccess\Doctor.cs" /> <Compile Include="DatabaseAccess\Doctor.cs" />
<Compile Include="DatabaseAccess\Origin.cs" /> <Compile Include="DatabaseAccess\Origin.cs" />
<Compile Include="DatabaseAccess\Origin_Exam.cs" /> <Compile Include="DatabaseAccess\Origin_Exam.cs" />

View File

@ -27,7 +27,7 @@
<%--https://stackoverflow.com/questions/8703317/troubleshooting-jquery-ajax-call-using-generic-handler-in-asp-net--%> <%--https://stackoverflow.com/questions/8703317/troubleshooting-jquery-ajax-call-using-generic-handler-in-asp-net--%>
<%--https://codepedia.info/jquery-ajax-json-example-asp-net-sql-database/--%> <%--https://codepedia.info/jquery-ajax-json-example-asp-net-sql-database/--%>
<script type="text/javascript"> <%-- <script type="text/javascript">
$(function () { $(function () {
$("#myButton").on("click", function (e) { $("#myButton").on("click", function (e) {
console.log("inside_myButton_onClick"); console.log("inside_myButton_onClick");
@ -56,20 +56,20 @@
} }
}); });
}); });
</script> </script>--%>
</head> </head>
<body> <body>
<form id="form1" runat="server"> <form id="form1" runat="server">
<div> <div>
<h1>EHEC Clusteranalysis</h1> <h1>EHEC Clusteranalysis</h1>
</div> </div>
<select id="ddlSelectYear"> <%--<select id="ddlSelectYear">
<option>2014</option> <option>2014</option>
<option>2015</option> <option>2015</option>
</select> </select>
<button id="myButton" style="color:DodgerBlue;font-weight:bold;height:45px;width:150px;">Get Cluster Data</button> <button id="myButton" style="color:DodgerBlue;font-weight:bold;height:45px;width:150px;">Get Cluster Data</button>
<div id="contentHolder"></div> <div id="contentHolder"></div>--%>
<%-- <asp:Button <asp:Button
ID="Button1" ID="Button1"
runat="server" runat="server"
Text="First Button" Text="First Button"
@ -78,7 +78,7 @@
ForeColor="DodgerBlue" ForeColor="DodgerBlue"
Height="45" Height="45"
Width="150" Width="150"
/>--%> />
</form> </form>
<div class="alchemy" id="alchemy"></div> <div class="alchemy" id="alchemy"></div>
@ -87,16 +87,16 @@
//$json = file_get_contents($url); //$json = file_get_contents($url);
//$data = json_decode($json); //$data = json_decode($json);
var config = { var config = {
dataSource: "C:\Users\Public\Documents\cluster.json", dataSource: "<%=Clusterdata%>",
forceLocked: true, forceLocked: true,
graphHeight: function(){ return 800; }, graphHeight: function(){ return 800; },
graphWidth: function(){ return 800; }, graphWidth: function(){ return 800; },
linkDistance: function(){ return 50; }, linkDistance: function(){ return 50; },
nodeTypes: { nodeTypes: {
"node_type": [ "Nodetype": [
"Maintainer", "Patient",
"Contributor", "Result",
"none" "Origin"
] ]
}, },
nodeMouseOver: 'fun_fact', nodeMouseOver: 'fun_fact',

View File

@ -9,15 +9,16 @@ namespace EHEC_Server
{ {
public partial class cluster : System.Web.UI.Page public partial class cluster : System.Web.UI.Page
{ {
protected string Clusterdata { get; set; }
ClusterConverter cc = new ClusterConverter();
protected void Page_Load(object sender, EventArgs e) protected void Page_Load(object sender, EventArgs e)
{ {
Clusterdata = cc.WriteJson();
} }
//protected void Button1_Click(object sender, EventArgs e) protected void Button1_Click(object sender, EventArgs e)
//{ {
// ClusterConverter cc = new ClusterConverter(); Clusterdata = cc.WriteJson();
// cc.WriteJson(); }
//}
} }
} }

View File

@ -20,5 +20,14 @@ namespace EHEC_Server {
/// To modify move field declaration from designer file to code-behind file. /// To modify move field declaration from designer file to code-behind file.
/// </remarks> /// </remarks>
protected global::System.Web.UI.HtmlControls.HtmlForm form1; protected global::System.Web.UI.HtmlControls.HtmlForm form1;
/// <summary>
/// Button1 control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.Button Button1;
} }
} }

View File

@ -9,32 +9,38 @@ namespace EHEC_Server
{ {
public class ClusterConverter public class ClusterConverter
{ {
protected string Json { get; set; }
public string WriteJson() public string WriteJson()
{ {
ClusterPatient p = new ClusterPatient(); var Json = JsonConverter.Serialize(GetCluster());
List<ClusterPatient> clusterPatientsList = new List<ClusterPatient>(); //ClusterPatient p = new ClusterPatient();
clusterPatientsList = p.GetClusterPatients(); //List<ClusterPatient> clusterPatientsList = new List<ClusterPatient>();
ClusterResult r = new ClusterResult(); //clusterPatientsList = p.GetClusterPatients();
List<ClusterResult> clusterResultsList = new List<ClusterResult>(); //ClusterResult r = new ClusterResult();
clusterResultsList = r.GetClusterResults(); //List<ClusterResult> clusterResultsList = new List<ClusterResult>();
//clusterResultsList = r.GetClusterResults();
//var json = JsonConverter.Serialize(clusterPatientsList); System.IO.File.WriteAllText(@"C: \Users\novski\Desktop\cluster.json", Json);
//string path = System.Reflection.Assembly.GetExecutingAssembly().Location; return Json; //= JsonConverter.Serialize(clusterPatientsList);
//string fileName = Path.Combine(path, "ClusterData.json");
//System.IO.File.WriteAllText(fileName, json);
var json = JsonConverter.Serialize(clusterPatientsList);
System.IO.File.WriteAllText(@"C:\Users\Public\Documents\cluster.json", json);
return json;
} }
private List<ClusterPatient> GetCluster() private Cluster GetCluster()
{ {
return new List<ClusterPatient>(); return new Cluster
{
Comment = "some comment",
Nodes = new List<Node>
{
new Node
{
Node get = new Node();
List <Node> xs = new List<Node>();
}
Nodes.add(getClusterPatients()) // irrgend sowas...
}
};
} }
} }
} }

View File

@ -0,0 +1,14 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EHEC_Server
{
public class Cluster
{
public string Comment { get; set; }
public List<Node> Nodes { get; set; }
public List<Edges> Edges { get; set; }
}
}

View File

@ -11,28 +11,28 @@ namespace EHEC_Server
/// </summary> /// </summary>
public class ClusterOrigin public class ClusterOrigin
{ {
public int Id { get; set; } //public int Id { get; set; }
public string Name { get; set; } //public string Name { get; set; }
public string Nodetype { get; set; } //public string Nodetype { get; set; }
public ClusterOrigin() { } //public ClusterOrigin() { }
public List<ClusterOrigin> GetClusterOrigins() //public List<ClusterOrigin> GetClusterOrigins()
{ //{
Origin origin = new Origin(); // Origin origin = new Origin();
List<Origin> origins = new List<Origin>(); // List<Origin> origins = new List<Origin>();
origins = origin.GetAllOrigins(); // origins = origin.GetAllOrigins();
List<ClusterOrigin> clusterOrigins = new List<ClusterOrigin>(); // List<ClusterOrigin> clusterOrigins = new List<ClusterOrigin>();
foreach (Origin element in origins) // foreach (Origin element in origins)
{ // {
ClusterOrigin clusterOrigin = new ClusterOrigin // ClusterOrigin clusterOrigin = new ClusterOrigin
{ // {
Id = element.OriginId, // Id = element.OriginId,
Nodetype = "origin", // Nodetype = "origin",
Name = element.City // Name = element.City
}; // };
clusterOrigins.Add(clusterOrigin); // clusterOrigins.Add(clusterOrigin);
}; // };
return clusterOrigins; // return clusterOrigins;
} //}
} }
} }

View File

@ -11,28 +11,28 @@ namespace EHEC_Server
/// </summary> /// </summary>
public class ClusterPatient public class ClusterPatient
{ {
public int Id { get; set; } //public int Id { get; set; }
public string Name { get; set; } //public string Name { get; set; }
public string Nodetype { get; set; } //public string Nodetype { get; set; }
public ClusterPatient() { } //public ClusterPatient() { }
public List<ClusterPatient> GetClusterPatients() //public List<ClusterPatient> GetClusterPatients()
{ //{
Patient patient = new Patient(); // Patient patient = new Patient();
List<Patient> patients = new List<Patient>(); // List<Patient> patients = new List<Patient>();
patients = patient.GetAllPatients(); // patients = patient.GetAllPatients();
List<ClusterPatient> clusterPatients = new List<ClusterPatient>(); // List<ClusterPatient> clusterPatients = new List<ClusterPatient>();
foreach (Patient element in patients) // foreach (Patient element in patients)
{ // {
ClusterPatient clusterPatient = new ClusterPatient // ClusterPatient clusterPatient = new ClusterPatient
{ // {
Id = element.PatientId, // Id = element.PatientId,
Nodetype = "patient", // Nodetype = "patient",
Name = element.FirstName + " " + element.LastName // Name = element.FirstName + " " + element.LastName
}; // };
clusterPatients.Add(clusterPatient); // clusterPatients.Add(clusterPatient);
} // }
return clusterPatients; // return clusterPatients;
} //}
} }
} }

View File

@ -11,28 +11,28 @@ namespace EHEC_Server
/// </summary> /// </summary>
public class ClusterResult public class ClusterResult
{ {
public int Id { get; set; } //public int Id { get; set; }
public string Name { get; set; } //public string Name { get; set; }
public string Nodetype { get; set; } //public string Nodetype { get; set; }
public ClusterResult() { } //public ClusterResult() { }
public List<ClusterResult> GetClusterResults() //public List<ClusterResult> GetClusterResults()
{ //{
Result result = new Result(); // Result result = new Result();
List<Result> results = new List<Result>(); // List<Result> results = new List<Result>();
results = result.GetAllResults(); // results = result.GetAllResults();
List<ClusterResult> clusterResults = new List<ClusterResult>(); // List<ClusterResult> clusterResults = new List<ClusterResult>();
foreach (Result element in results) // foreach (Result element in results)
{ // {
ClusterResult clusterResult = new ClusterResult // ClusterResult clusterResult = new ClusterResult
{ // {
Id = element.ResultId, // Id = element.ResultId,
Nodetype = "result", // Nodetype = "result",
Name = element.Name // Name = element.Name
}; // };
clusterResults.Add(clusterResult); // clusterResults.Add(clusterResult);
}; // };
return clusterResults; // return clusterResults;
} //}
} }
} }

View File

@ -0,0 +1,72 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EHEC_Server
{
public class Edges
{
public int Source { get; set; }
public int Target { get; set; }
public string Edgetype { get; set; }
public Edges() { }
public List<Edges> GetClusterRelationsPatientsOrigins()
{
Exam exam = new Exam();
List<Exam> exams = new List<Exam>();
exams = exam.GetAllExams();
List<Edges> clusterEdges = new List<Edges>();
foreach (Exam element in exams)
{
Edges clusterEdge = new Edges
{
Edgetype = "Angesteckt in ",
Source = element.PatientId,
Target = element.DoctorId ///for tests !!!!!!!!!!!!!!!! correct it to Origin id somehow!!!!!!!!
};
clusterEdges.Add(clusterEdge);
}
return clusterEdges;
}
public List<Edges> GetClusterRelationsPatientsResults()
{
Exam exam = new Exam();
List<Exam> exams = new List<Exam>();
exams = exam.GetAllExams();
List<Edges> clusterEdges = new List<Edges>();
foreach (Exam element in exams)
{
Edges clusterEdge = new Edges
{
Edgetype = "Wurde Angesteckt mit ",
Source = element.PatientId,
Target = element.ResultId
};
clusterEdges.Add(clusterEdge);
};
return clusterEdges;
}
//public List<Edges> GetClusterRelationOrigin()
//{
// Origin origin = new Origin();
// List<Origin> origins = new List<Origin>();
// origins = origin.GetAllOrigins();
// List<Edges> clusterOrigins = new List<Edges>();
// foreach (Origin element in origins)
// {
// Nodes clusterOrigin = new Nodes
// {
// Nodetype = "Angesteckt in ",
// Source = element.OriginId,
// Target = element.City
// };
// clusterOrigins.Add(clusterOrigin);
// };
// return clusterOrigins;
//}
}
}

View File

@ -0,0 +1,78 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace EHEC_Server
{
public class Node
{
public int Id { get; set; }
public string Name { get; set; }
public string Nodetype { get; set; }
public Node() { }
public List<Node> GetNodes()
{
List<Node> X = new List<Node>();
X.AddRange(GetClusterOrigins());
X.AddRange(GetClusterPatients());
X.AddRange(GetClusterResults());
return X;
}
public List<Node> GetClusterOrigins()
{
Origin origin = new Origin();
List<Origin> origins = new List<Origin>();
origins = origin.GetAllOrigins();
List<Node> clusterOrigins = new List<Node>();
foreach (Origin element in origins)
{
Node clusterOrigin = new Node
{
Id = element.OriginId,
Nodetype = "origin",
Name = element.City
};
clusterOrigins.Add(clusterOrigin);
};
return clusterOrigins;
}
public List<Node> GetClusterPatients()
{
Patient patient = new Patient();
List<Patient> patients = new List<Patient>();
patients = patient.GetAllPatients();
List<Node> clusterPatients = new List<Node>();
foreach (Patient element in patients)
{
Node clusterPatient = new Node
{
Id = element.PatientId,
Nodetype = "patient",
Name = element.FirstName + " " + element.LastName
};
clusterPatients.Add(clusterPatient);
}
return clusterPatients;
}
public List<Node> GetClusterResults()
{
Result result = new Result();
List<Result> results = new List<Result>();
results = result.GetAllResults();
List<Node> clusterResults = new List<Node>();
foreach (Result element in results)
{
Node clusterResult = new Node
{
Id = element.ResultId,
Nodetype = "result",
Name = element.Name
};
clusterResults.Add(clusterResult);
};
return clusterResults;
}
}
}