Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev justin #33

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions src/soap/handlers/GetValues.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export async function* getValues(
yield encodeXML(
sourceInfoStart() +
siteInfoType({
hasAttribute: true,
organizationRefsMap,
refsMap: stationRefsMap,
station
Expand Down Expand Up @@ -242,14 +243,19 @@ export async function* getValues(
refsMap.get('his.odm.qualitycontrollevels.QualityControlLevelCode')
const methodID = refsMap.get('his.odm.methods.MethodID')
const sourceID = refsMap.get('his.odm.sources.SourceID')
const queryUTCOffset = refsMap && refsMap.get('his.wof.query.UTCOffset')

const datapointsParams = Object.assign({
datastream_id: datastreamValue._id,
time: {
$gte: startTime,
$lte: endTime
$gte: parseInt(queryUTCOffset)
? startTime - parseInt(queryUTCOffset)
: startTime,
$lte: parseInt(queryUTCOffset)
? endTime - parseInt(queryUTCOffset)
: endTime
},
time_local: true,
time_local: !parseInt(queryUTCOffset),
t_int: true,
$limit: 2016,
$sort: {
Expand Down Expand Up @@ -333,8 +339,12 @@ export async function* getValues(
'datapoints',
Object.assign(datapointsParams, {
time: {
$gt: datapoints[datapoints.length - 1].lt,
$lte: endTime
$gt: parseInt(queryUTCOffset)
? datapoints[datapoints.length - 1].t
: datapoints[datapoints.length - 1].lt,
$lte: parseInt(queryUTCOffset)
? endTime - parseInt(queryUTCOffset)
: endTime
}
})
)
Expand Down
19 changes: 14 additions & 5 deletions src/soap/handlers/GetValuesForASiteObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,19 @@ export async function* getValuesForASiteObject(
)
const methodID = dataRefsMap.get('his.odm.methods.MethodID')
const sourceID = dataRefsMap.get('his.odm.sources.SourceID')
const queryUTCOffset = refsMap && refsMap.get('his.wof.query.UTCOffset')

const datapointsParams = Object.assign({
datastream_id: data._id,
time: {
$gte: startTime,
$lte: endTime
$gte: parseInt(queryUTCOffset)
? startTime - parseInt(queryUTCOffset)
: startTime,
$lte: parseInt(queryUTCOffset)
? endTime - parseInt(queryUTCOffset)
: endTime
},
time_local: true,
time_local: !parseInt(queryUTCOffset),
t_int: true,
$limit: 2016,
$sort: {
Expand Down Expand Up @@ -300,8 +305,12 @@ export async function* getValuesForASiteObject(
'datapoints',
Object.assign(datapointsParams, {
time: {
$gt: datapoints[datapoints.length - 1].lt,
$lte: endTime
$gt: parseInt(queryUTCOffset)
? datapoints[datapoints.length - 1].t
: datapoints[datapoints.length - 1].lt,
$lte: parseInt(queryUTCOffset)
? endTime - parseInt(queryUTCOffset)
: endTime
}
})
)
Expand Down
26 changes: 20 additions & 6 deletions src/soap/handlers/GetValuesObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,12 @@ export async function* getValuesObject(
// Will only be one station since $limit=1
for (const station of stations) {
yield sourceInfoStart() +
siteInfoType({ organizationRefsMap, refsMap: stationRefsMap, station }) +
siteInfoType({
hasAttribute: true,
organizationRefsMap,
refsMap: stationRefsMap,
station
}) +
sourceInfoEnd()
}

Expand Down Expand Up @@ -228,14 +233,19 @@ export async function* getValuesObject(
refsMap.get('his.odm.qualitycontrollevels.QualityControlLevelCode')
const methodID = refsMap.get('his.odm.methods.MethodID')
const sourceID = refsMap.get('his.odm.sources.SourceID')
const queryUTCOffset = refsMap && refsMap.get('his.wof.query.UTCOffset')

const datapointsParams = Object.assign({
datastream_id: datastreamValue._id,
time: {
$gte: startTime,
$lte: endTime
$gte: parseInt(queryUTCOffset)
? startTime - parseInt(queryUTCOffset)
: startTime,
$lte: parseInt(queryUTCOffset)
? endTime - parseInt(queryUTCOffset)
: endTime
},
time_local: true,
time_local: !parseInt(queryUTCOffset),
t_int: true,
$limit: 2016,
$sort: {
Expand Down Expand Up @@ -317,8 +327,12 @@ export async function* getValuesObject(
'datapoints',
Object.assign(datapointsParams, {
time: {
$gt: datapoints[datapoints.length - 1].lt,
$lte: endTime
$gt: parseInt(queryUTCOffset)
? datapoints[datapoints.length - 1].t
: datapoints[datapoints.length - 1].lt,
$lte: parseInt(queryUTCOffset)
? endTime - parseInt(queryUTCOffset)
: endTime
}
})
)
Expand Down
39 changes: 27 additions & 12 deletions src/soap/serializers/site.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ export function siteInfoEnd() {
return '</siteInfo>'
}

export function siteInfoType({ organizationRefsMap, refsMap, station }) {
export function siteInfoType({
hasAttribute = false,
organizationRefsMap,
refsMap,
station
}) {
const siteId = refsMap && refsMap.get('his.odm.sites.SiteID')
const siteCode = refsMap && refsMap.get('his.odm.sites.SiteCode')
const verticalDatum = refsMap && refsMap.get('his.odm.sites.VerticalDatum')
Expand Down Expand Up @@ -64,17 +69,27 @@ export function siteInfoType({ organizationRefsMap, refsMap, station }) {
(verticalDatum
? `<verticalDatum>${encodeXML(verticalDatum)}</verticalDatum>`
: '') +
(county
? `<siteProperty name="County">${encodeXML(county)}</siteProperty>`
: '') +
(state
? `<siteProperty name="State">${encodeXML(state)}</siteProperty>`
: '') +
(comments
? `<siteProperty name="Site Comments">${encodeXML(
comments
)}</siteProperty>`
: '') +
`${
hasAttribute || county
? `<siteProperty name="County">${
county ? encodeXML(county) : ''
}</siteProperty>`
: ''
}` +
`${
hasAttribute || county
? `<siteProperty name="State">${
state ? encodeXML(state) : ''
}</siteProperty>`
: ''
}` +
`${
hasAttribute || comments
? `<siteProperty name="Site Comments">${
comments ? encodeXML(comments) : ''
}</siteProperty>`
: ''
}` +
(posAccuracyM
? `<siteProperty name="PosAccuracy_m">${encodeXML(
posAccuracyM
Expand Down
34 changes: 34 additions & 0 deletions test/spec/02/site.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,40 @@ describe('Serializers', function () {
)
})

it('should serialize siteInfoType with siteProperty flavor 1', function () {
expect(
siteInfoType({
hasAttribute: true,
station: {
name: 'SiteName-full'
}
})
).to.equal(
'<siteName>SiteName-full</siteName>' +
'<siteProperty name="County"></siteProperty>' +
'<siteProperty name="State"></siteProperty>' +
'<siteProperty name="Site Comments"></siteProperty>'
)
})

it('should serialize siteInfoType with siteProperty flavor 2', function () {
const refsMap = new Map([['his.odm.sites.State', 'Massachusetts']])
expect(
siteInfoType({
hasAttribute: true,
station: {
name: 'SiteName-full'
},
refsMap
})
).to.equal(
'<siteName>SiteName-full</siteName>' +
'<siteProperty name="County"></siteProperty>' +
'<siteProperty name="State">Massachusetts</siteProperty>' +
'<siteProperty name="Site Comments"></siteProperty>'
)
})

it('should serialize siteInfoType without externalRefs', function () {
expect(
siteInfoType({
Expand Down