UNPKG

1.35 kBJavaScriptView Raw
1const fc = require('./example_fc.json')
2const fs = require('fs')
3const path = require('path')
4const LoremIpsum = require('lorem-ipsum').LoremIpsum
5
6const lorem = new LoremIpsum({
7 sentencesPerParagraph: {
8 max: 3,
9 min: 1
10 },
11 wordsPerSentence: {
12 max: 9,
13 min: 4
14 }
15})
16
17const observations = fc.features.map(f => {
18 const observation = {
19 id: f.id,
20 lon: f.geometry && f.geometry.coordinates[0],
21 lat: f.geometry && f.geometry.coordinates[1],
22 created_at: f.properties.start,
23 attachments: Array(randomInt(5))
24 .fill()
25 .map(() => ({
26 id: randomId() + '.jpg',
27 type: 'image/jpg'
28 })),
29 tags: {}
30 }
31 const omit = ['id', 'picture', 'pictures']
32
33 for (const key in f.properties) {
34 if (omit.includes(key)) continue
35 if (Array.isArray(f.properties[key])) continue
36 observation.tags[key] = f.properties[key]
37 }
38 observation.tags.notes = lorem.generateParagraphs(1)
39 if (f.properties.happening && f.properties.happening[0]) {
40 observation.tags.categoryId = f.properties.happening[0]
41 }
42
43 return observation
44})
45
46function randomInt(max) {
47 return Math.ceil(Math.random() * max)
48}
49
50function randomId() {
51 return Math.ceil(Math.random() * Math.pow(2, 32)).toString(16)
52}
53
54fs.writeFileSync(
55 path.join(__dirname, '/observations.json'),
56 JSON.stringify(observations, null, 2)
57)