suro | Netflix 's distributed Data Pipeline | Architecture library
kandi X-RAY | suro Summary
Support
Quality
Security
License
Reuse
- The comparison function
- getter for tokens
- Creates the runnable from the given message .
- Creates runnable .
- Stops the message processor .
- Poll for messages .
- Start uploading a file .
- Sends a message to the producer .
- Start the consumer .
- Create a runnable poller
suro Key Features
suro Examples and Code Snippets
Trending Discussions on suro
Trending Discussions on suro
QUESTION
I have 2 json objects (covidResults and infoResults) and I want to merge them if codcentre are the same in both objects. I want to get the result like this (finalResults), where: totalSchoolsByRegion: is the total of schools in concatResults and totalCovidRegion: are the number of schools in each region that their condition estat==='Confinat'
finalResults = {
{codeRegion: "01", regionName: "Baix Empordà", totalSchoolsByRegion: 2, totalCovidRegion: 0},
{codeRegion: "02", regionName: "Alt Empordà", totalSchoolsByRegion: 2, totalCovidRegion: 1},
{codeRegion: "03", regionName: "Alta Ribagorça", totalSchoolsByRegion: 3, totalCovidRegion: 2},
But in newObjectResults i have empty slots, and I can get all the information, because I have undefined results
MY CODE
const covidResults = [
{ datageneracio: "2020-09-23T00:00:00.000",
codcentre: "17010402",
estat: "Obert",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{ datageneracio: "2020-09-23T00:00:00.000",
codcentre: "17010384",
estat: "Obert",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{ datageneracio: "2020-09-23T00:00:00.000",
codcentre: "17008948",
estat: "Confinat",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{
datageneracio: "2020-09-23T00:00:00.000",
codcentre: "17008900",
estat: "Obert",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{ datageneracio: "2020-09-23T00:00:00.000",
codcentre: "8000131",
estat: "Confinat",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{ datageneracio: "2020-09-23T00:00:00.000",
codcentre: "8000153",
estat: "Obert",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{ datageneracio: "2020-09-23T00:00:00.000",
codcentre: "8000165",
estat: "Confinat",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
}
];
const infoResults = [
{ codcentre: "17010402",
name: "Llar d'infants Municipal La Bòbila",
address: "av. de Can Caramany, s/n",
codi_postal: "17121",
regionName: "Baix Empordà",
codeRegion: "10",
city: "Corçà",
long: "3.014146876",
lat: "41.98864073"
},
{ codcentre: "17010384",
name: "L'Energia-C.aut.ens.art.pro.de Música Palafrugell",
address: "Pi i Margall,114/Manufactur.Suro,51-67",
codi_postal: "17200",
regionName: "Baix Empordà",
codeRegion: "10",
city: "Palafrugell",
long: "3.164713218",
lat: "41.921198948"
},
{ codcentre: "17008948",
name: "Llar d'infants Els Nins",
address: "pl. Onze de Setembre, 1",
codi_postal: "17493",
regionName: "Alt Empordà",
codeRegion: "02",
city: "Vilajuïga",
long: "3.094177279",
lat: "42.327433814"
},
{ codcentre: "17008900",
name: "Llar d'infants de Cabanes",
address: "c. Colon, 8",
codi_postal: "17761",
regionName: "Alt Empordà",
codeRegion: "02",
city: "Cabanes",
long: "2.977203057",
lat: "42.30876845"
},
{ codcentre: "08000131",
name: "La Presentació",
address: "c. Pompeu Fabra, 2",
codi_postal: "08350",
regionName: "Maresme",
codeRegion: "21",
city: "Arenys de Mar",
long: "2.547075835",
lat: "41.585754015"
},
{ codcentre: "08000153",
name: "Escola Joan Maragall",
address: "c. Riera Sa Clavella, s/n",
codi_postal: "08350",
regionName: "Maresme",
codeRegion: "21",
city: "Arenys de Mar",
long: "2.54631495",
lat: "41.582404768"
},
{
codcentre: "08000165",
name: "Escola Sant Martí",
address: "c. Generalitat, 2",
codi_postal: "08358",
regionName: "Maresme",
codeRegion: "21",
city: "Arenys de Munt",
long: "2.53853995",
lat: "41.609034581"
}
];
let concatResults = [];
covidResults.forEach(function (item) {
return infoResults.map(school => {
if (infoResults !== undefined && school.codcentre === item.codcentre) {
concatResults.push({
estat: item.estat,
codecentre: item.codcentre,
regionName: school.regionName,
codeRegion: school.codeRegion,
name: school.name
});
}
});
});
let newObjectResults = [];
concatResults.forEach(item => {
if (!newObjectResults.hasOwnProperty(item.codeRegion)) {
newObjectResults[item.codeRegion] = {
codeRegion: item.codeRegion,
regionName: item.regionName,
schools: []
};
}
newObjectResults[item.codeRegion].schools.push({
codecentre: item.codecentre,
estat: item.estat
});
});
console.log("newObjectResults", newObjectResults);
let finalResults = [];
let totalCovidRegion = 0;
newObjectResults.map(item => {
if (item !== undefined) {
finalResults.push({
codeRegion: item.codeRegion,
regionName: item.regionName,
totalSchoolsByRegion: item.schools.length,
totalCovidRegion
});
item.schools.map(it => {
if (it.estat === "Confinat") {
totalCovidRegion += 1;
}
});
}
});
console.log("finalResults", finalResults);
ANSWER
Answered 2020-Nov-09 at 16:57You dont have to use loops to do this and your undefined is cause by unmatching codcentre which starts with 0 so i did a parseInt before comparing.
You can do a map and reduce which would give you the expected results like below.
const covidResults = [{
datageneracio: "2020-09-23T00:00:00.000",
codcentre: "17010402",
estat: "Obert",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{
datageneracio: "2020-09-23T00:00:00.000",
codcentre: "17010384",
estat: "Obert",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{
datageneracio: "2020-09-23T00:00:00.000",
codcentre: "17008948",
estat: "Confinat",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{
datageneracio: "2020-09-23T00:00:00.000",
codcentre: "17008900",
estat: "Obert",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{
datageneracio: "2020-09-23T00:00:00.000",
codcentre: "8000131",
estat: "Confinat",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{
datageneracio: "2020-09-23T00:00:00.000",
codcentre: "8000153",
estat: "Obert",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
},
{
datageneracio: "2020-09-23T00:00:00.000",
codcentre: "8000165",
estat: "Confinat",
grup_confin: "0",
alumn_confin: "0",
docent_confin: "0",
altres_confin: "0"
}
];
const infoResults = [{
codcentre: "17010402",
name: "Llar d'infants Municipal La Bòbila",
address: "av. de Can Caramany, s/n",
codi_postal: "17121",
regionName: "Baix Empordà",
codeRegion: "10",
city: "Corçà",
long: "3.014146876",
lat: "41.98864073"
},
{
codcentre: "17010384",
name: "L'Energia-C.aut.ens.art.pro.de Música Palafrugell",
address: "Pi i Margall,114/Manufactur.Suro,51-67",
codi_postal: "17200",
regionName: "Baix Empordà",
codeRegion: "10",
city: "Palafrugell",
long: "3.164713218",
lat: "41.921198948"
},
{
codcentre: "17008948",
name: "Llar d'infants Els Nins",
address: "pl. Onze de Setembre, 1",
codi_postal: "17493",
regionName: "Alt Empordà",
codeRegion: "02",
city: "Vilajuïga",
long: "3.094177279",
lat: "42.327433814"
},
{
codcentre: "17008900",
name: "Llar d'infants de Cabanes",
address: "c. Colon, 8",
codi_postal: "17761",
regionName: "Alt Empordà",
codeRegion: "02",
city: "Cabanes",
long: "2.977203057",
lat: "42.30876845"
},
{
codcentre: "08000131",
name: "La Presentació",
address: "c. Pompeu Fabra, 2",
codi_postal: "08350",
regionName: "Maresme",
codeRegion: "21",
city: "Arenys de Mar",
long: "2.547075835",
lat: "41.585754015"
},
{
codcentre: "08000153",
name: "Escola Joan Maragall",
address: "c. Riera Sa Clavella, s/n",
codi_postal: "08350",
regionName: "Maresme",
codeRegion: "21",
city: "Arenys de Mar",
long: "2.54631495",
lat: "41.582404768"
},
{
codcentre: "08000165",
name: "Escola Sant Martí",
address: "c. Generalitat, 2",
codi_postal: "08358",
regionName: "Maresme",
codeRegion: "21",
city: "Arenys de Munt",
long: "2.53853995",
lat: "41.609034581"
}
];
const tempResults = covidResults.map(x => {
const y = infoResults.find(y => parseInt(y.codcentre) === parseInt(x.codcentre));
return { ...x,
...y
};
});
const output = tempResults.reduce((a, c) => {
const item = a.find(x => x.codeRegion === c.codeRegion);
if (item) {
item.totalSchoolsByRegion++;
item.totalCovidRegion += (c.estat === 'Confinat' ? 1 : 0)
} else {
a.push({
codeRegion: c.codeRegion,
regionName: c.regionName,
totalSchoolsByRegion: 1,
totalCovidRegion: c.estat === 'Confinat' ? 1 : 0
});
}
return a;
}, []);
console.log(output);
QUESTION
There are four tiles (path:41,row:35/path:41,row:36/path:42,row:35/path:42,row:36) of LANDSAT 8 surface reflectance that cover my study area. I want to remove only images(tile) with path 42 and row 36 from this collection. How can I do that? Here is my code:
Map.centerObject(table);
Map.addLayer(table);
var sd = '2015-01-01';//Start Date
var ed = '2016-01-01';//End Date
var suro = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(table)
.filterDate(sd,ed)
//.filter(ee.Filter.and(ee.Filter.notEquals('WRS_PATH',42),ee.Filter.notEquals('WRS_ROW',36)))
.filter(ee.Filter.lt('CLOUD_COVER', 45));
var sur = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(table)
.filterDate(sd,ed)
//.filter(ee.Filter.and(ee.Filter.notEquals('WRS_PATH',42),ee.Filter.notEquals('WRS_ROW',36)))
.filter(ee.Filter.lt('CLOUD_COVER', 45))
//Map a function to mask clouds and negative values
.map(function(img){
var idd = img.id();
// Bits 3 and 5 are cloud shadow and cloud, respectively.
var cloudShadowBitMask = 1 << 3;
var cloudsBitMask = 1 << 5;
// Get the pixel QA band.
var qa = img.select('pixel_qa');
// Both flags should be set to zero, indicating clear conditions.
var mask = qa.bitwiseAnd(cloudShadowBitMask).eq(0)
.and(qa.bitwiseAnd(cloudsBitMask).eq(0));
// Return the masked image, scaled to reflectance, without the QA bands.
var img2 = img.updateMask(mask).multiply(0.0001).select("B1").rename(idd);
//Mask negative values from images
var mask2 = img2.gt(0);
return img2.multiply(mask2);
})
.toBands()
.clip(table);
Map.addLayer(sur);
var imColl_sur = sur.getInfo().bands;
print(imColl_sur);
print(imColl_sur.length);
for (var i = 0; i < imColl_sur.length; i++) {
//Image Load
var im = sur.select(imColl_sur[i]["id"]);
//var id = imColl_sur[i]["id"];
//var im = ee.Image.load(id);
//Image Properties from original collection
var idl = suro.getInfo().features[i]["properties"]["LANDSAT_ID"];
var st = suro.getInfo().features[i]["properties"]["SENSING_TIME"];
var sza = (suro.getInfo().features[i]["properties"]["SOLAR_ZENITH_ANGLE"])
.toString();
//Download
Export.image.toDrive({
image: im,
description: 'L8_surReflectance_B1_'+idl.slice(10,26)
+st.slice(11,13)+st.slice(14,16)+'_'
+sza.slice(0,2)+sza.slice(3,8),
scale: 30,
region: table,
maxPixels: 1e9
});
}
ANSWER
Answered 2020-Jan-29 at 12:53Combining filters probably works somehow, and would be more elegant.
But you can use a second approach: create a new metadata variable combining ROW and PATH, and filter based on it:
var geometry = ee.Geometry({"type":"Polygon","coordinates":[[[-98.01249999999999,41.430123208731864],[-98.01249999999999,38.809492348693325],[-92.03593749999999,38.809492348693325],[-92.03593749999999,41.430123208731864]]],"geodesic":false,"evenOdd":true})
var sd = '2015-01-01';//Start Date
var ed = '2016-01-01';//End Date
var suro = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(geometry)
.filterDate(sd,ed)
.map(function(image){
return image.set({'WRS_PATHROW':{'path':image.get('WRS_PATH'),
'row':image.get('WRS_ROW')}
})})
.filter(ee.Filter.neq('WRS_PATHROW', {'path':25, 'row':32}))
You can combine two filters with an ee.Filter.and
to remove any images that have WRS_PATH=21
and WRS_ROW=32
:
var filters = ee.Filter.and(
ee.Filter.neq('WRS_PATH',21),
ee.Filter.neq('WRS_ROW',32)
);
var suro = ee.ImageCollection('LANDSAT/LC08/C01/T1_SR')
.filterBounds(geometry)
.filterDate(sd,ed)
.filter(filters);
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install suro
Support
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesExplore Kits - Develop, implement, customize Projects, Custom Functions and Applications with kandi kits
Save this library and start creating your kit
Share this Page