-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetail.cs
120 lines (106 loc) · 5.09 KB
/
Detail.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
using System;
using System.Collections.Generic;
using System.IO;
using Newtonsoft.Json;
namespace DatasetProg
{
internal class Detail
{
public void ConfirmDetails(List<StationData> results)
{
// creates new Url object
var u = new Url();
// 'results' stores data taken from external DB
results = u.ReadTable();
for (var i = 0; i < 33; i++)
{
// populate info with default values for Json-ld files
// using object initiator to create, instantiate & add attributes to each object
var contact = new ContactPoint
{
type = "ContactPoint",
contactType = "customer service",
telephone = "+353 9 138 7200",
email = "institute.mail@marine.ie"
};
var creator = new Creator
{
type = "Organization",
url = "http://www.marine.ie/Home/",
name =
"Marine Institute, State agency responsible for marine research, technology development and innovation in Ireland",
contactPoint = contact
};
var inc = new IncludedInDataCatalog
{
type = "DataCatalog",
name = "http://data.marine.ie/Category/Index/12"
};
// distribution info used to get direct file access
var dist1 = new Distribution
{
type = "DataDownload",
encodingFormat = "JSON",
contentUrl = results[i].Json
};
// e.g. "http://erddap.marine.ie/erddap/tabledap/IMI-TidePrediction.json?stationID,time,Water_Level,Water_Level_ODM,longitude,latitude&stationID=%22Achill_Island_MODELLED%22&time%3E=2017-01-01T00:00:00Z&time<=2020-01-01T00:20:00Z&longitude%3E=-10.27019&longitude<=-5.92167&latitude%3E=51.53115&latitude<=55.37168"; // get from DB
var dist2 = new Distribution
{
type = "DataDownload",
encodingFormat = "CSV",
contentUrl = results[i].Csv
};
// taken from DB
var g = new Geo
{
type = "GeoCoordinates",
longitude = results[i].Longitude,
latitude = results[i].Latitude
};
// e.g. "53.95219" & "-10.101596" - taken from DB
var spat = new SpatialCoverage
{
type = "Place",
geo = g
};
// object containing references to other JSON objects
var root = new Dataset
{
context = "http://schema.org/",
type = "Dataset",
name = "Marine Institute Tide Prediction",
description =
"Tidal predictions are generated from measured data via the Irish National Tide Gauge Network ...",
url = "http://data.marine.ie/Dataset/Details/20955",
sameAs = "http://data.marine.ie/Category/Index/12",
keywords = new List<string>
{
"OCEANOGRAPHY > TIDE > TIDAL WATER",
"OCEANOGRAPHY > TIDE > PREDICTIONS",
"OCEANOGRAPHY > TIDE > " + results[i].StationId
},
includedInDataCatalog = inc,
creator = creator,
distribution = new List<Distribution> {dist1, dist2},
temporalCoverage = "2017-01-01/2020-01-01",
spatialCoverage = spat
};
// keywords to be updated by method - pull station_id from DB to be entered in keywords List
// important for rest service as used to perform index search in PHP
// visual check shows data taken-in from DB
Console.WriteLine("Details Confirmed: " + g.longitude + " " + g.latitude);
// creation of List of type dataset with all the above info added using the Collections initializer
var oj = new List<Dataset> {root};
// added above set values in list to rendered JSON file - with indent formatting.
var json = JsonConvert.SerializeObject(oj, Formatting.Indented);
// as a check of the format - immediate output to console for viewing
Console.WriteLine(json);
// escape point here if format/output incorrect during testing
// Console.ReadKey();
// serialize JSON to a string and then write string to a file
File.WriteAllText(@"C:\Users\aconw\Downloads\JSONDirectory1\Dataset_" + results[i].StationId + ".jsonld",
JsonConvert.SerializeObject(oj, Formatting.Indented));
}
}
}
}