Skip to content

Commit

Permalink
separate migrazioni:
Browse files Browse the repository at this point in the history
* conferencerooms
* seminarcategories
* seminars
  • Loading branch information
paolini committed Oct 26, 2023
1 parent 4457918 commit 656598f
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 67 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "dm-manager",
"version": "1.3.2",
"version": "1.3.3",
"private": true,
"dependencies": {
"@fortawesome/fontawesome-svg-core": "^6.1.2",
Expand Down
2 changes: 1 addition & 1 deletion server/controllers/PersonController.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class PersonController extends Controller {
this.path = 'person'
this.managerRoles.push('person-manager')
this.supervisorRoles.push('person-manager', 'person-supervisor')
this.searchFields = [ 'lastName', 'firstName', 'affiliations.name' ]
this.searchFields = [ 'lastName', 'firstName', 'affiliations.name', 'notes' ]
this.searchRoles.push(...PERSON_SEARCH_ROLES)
this.queryPipeline.push(...Staff.personStaffPipeline())
}
Expand Down
148 changes: 84 additions & 64 deletions server/migrations.js
Original file line number Diff line number Diff line change
Expand Up @@ -388,32 +388,40 @@ const migrations = {
return true
},

D20231013_copy_events_13: async function(db) {
const people = db.collection('people')
const conferences = db.collection('eventconferences')
const seminars = db.collection('eventseminars')
const conferencerooms = db.collection('conferencerooms')
D20231026_init_seminarcategories_1: async function(db) {
const seminarcategories = db.collection('seminarcategories')

toUTCDate = s => {
const sd = new Date(s * 1000)
const date = new Date(sd.getFullYear(), sd.getUTCMonth(), sd.getUTCDate(), sd.getUTCHours(), sd.getUTCMinutes())
return date
}

categoryToSSD = c => {
return {
'198': 'MAT/01',
'162': 'MAT/02',
'152': 'MAT/03',
'200': 'MAT/04',
'114': 'MAT/05',
'190': 'MAT/06',
'191': 'MAT/07',
'154': 'MAT/08'
}[c];
}
const category_mapping = {
"colloquium": 175,
"algebra-seminar": 3,
"algebraic-and-arithmetic-geometry-seminar": 75,
"analysis-seminar": 159,
"analysis-seminar2": 77,
"baby-geometri-seminar": 79,
"dynamical-systems-seminar": 78,
"geometry-seminar": 85,
"il-teorema-piu-bello": 5,
"logic-seminar": 23,
"mathematical-physics-seminar": 6,
"number-theory-seminar": 7,
"probability-stochastic-analysis-statistics-seminar": 73,
"seminar-on-combinatorics-and-lie-theory-and-topology": 33,
"seminar-on-numerical-analysis": 63,
"seminari-map": 21,
}
await seminarcategories.deleteMany({})

for (const [category, label] of Object.entries(category_mapping)) {
await seminarcategories.insertOne({
name: category,
label: category,
})
}
return true
},

D20231026_init_conferencerooms_2: async function(db) {
const conferencerooms = db.collection('conferencerooms')
const room_mapping = {
'Department of Mathematics, Aula Seminari.': 'Aula Seminari (DM)',
'Aula Magna': 'Aula Magna (DM)',
Expand Down Expand Up @@ -535,59 +543,71 @@ const migrations = {
Online: 'Online',
Teams: 'Teams',
}

const category_mapping = {
"colloquium": 175,
"algebra-seminar": 3,
"algebraic-and-arithmetic-geometry-seminar": 75,
"analysis-seminar": 159,
"analysis-seminar2": 77,
"baby-geometri-seminar": 79,
"dynamical-systems-seminar": 78,
"geometry-seminar": 85,
"il-teorema-piu-bello": 5,
"logic-seminar": 23,
"mathematical-physics-seminar": 6,
"number-theory-seminar": 7,
"probability-stochastic-analysis-statistics-seminar": 73,
"seminar-on-combinatorics-and-lie-theory-and-topology": 33,
"seminar-on-numerical-analysis": 63,
"seminari-map": 21,

const name2names = {}

for (const [room_key, room_name] of Object.entries(room_mapping)) {
if (!name2names[room_name]) name2names[room_name] = []
name2names[room_name].push(room_key)
}

await people.deleteMany({created_by_migration: true})
await conferences.deleteMany({})
await conferencerooms.deleteMany({})
await seminars.deleteMany({})
await seminarcategories.deleteMany({})

const created_rooms = {}
for (const [name, names] of Object.entries(name2names)) {
await conferencerooms.insertOne({
name,
names,
})
}

for (const [room_key, room_name] of Object.entries(room_mapping)) {
if (created_rooms[room_name] === undefined) {
const newroom = await conferencerooms.insertOne({
name: room_name,
})
return true
},

created_rooms[room_name] = newroom.insertedId
D20231013_copy_events_14: async function(db) {
const people = db.collection('people')
const conferences = db.collection('eventconferences')
const seminars = db.collection('eventseminars')
const conferencerooms = db.collection('conferencerooms')
const seminarcategories = db.collection('seminarcategories')

const created_categories = {}

for (let seminarcategory of await seminarcategories.find({}).toArray()) {
created_categories[seminarcategory.label] = seminarcategory._id
}

const room_mapping = {}

for (const room of await conferencerooms.find({}).toArray()) {
for (const name of room.names) {
room_mapping[name] = room._id
}
}

const created_categories = {}
toUTCDate = s => {
const sd = new Date(s * 1000)
const date = new Date(sd.getFullYear(), sd.getUTCMonth(), sd.getUTCDate(), sd.getUTCHours(), sd.getUTCMinutes())
return date
}

for (const [category, label] of Object.entries(category_mapping)) {
const newcategory = await seminarcategories.insertOne({
name: category,
label: `${label}`,
})
const find = await seminarcategories.findOne({ label : `${label}`})
created_categories[label] = find._id
categoryToSSD = c => {
return {
'198': 'MAT/01',
'162': 'MAT/02',
'152': 'MAT/03',
'200': 'MAT/04',
'114': 'MAT/05',
'190': 'MAT/06',
'191': 'MAT/07',
'154': 'MAT/08'
}[c];
}

const lst = (await seminarcategories.find()).toArray()
console.log(JSON.stringify({lst}))

await people.deleteMany({created_by_migration: true})
await conferences.deleteMany({})
await seminars.deleteMany({})

console.log(JSON.stringify({created_categories}))

var offset = 0;
const batch_size = 97;
Expand All @@ -599,7 +619,7 @@ const migrations = {
for (const event of events) {
const taxonomy = event.unipievents_taxonomy
const title = he.decode(event.title.rendered)
const conferenceRoom = created_rooms[room_mapping[event.unipievents_place]]
const conferenceRoom = room_mapping[event.unipievents_place]
const startDatetime = toUTCDate(event.unipievents_startdate)
const duration = (event.unipievents_enddate - event.unipievents_startdate) / 60
const notes = event.content.rendered
Expand Down
2 changes: 1 addition & 1 deletion server/models/ConferenceRoom.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const {
const schema = new Schema({
name: { type: String, label: 'Nome', required: true, default: 'Aula ???' },
room: { type: ObjectId, label: 'Stanza', ref: 'Room' },

names: { type: [String], label: 'Nomi alternativi' },
createdBy,
updatedBy,
})
Expand Down

0 comments on commit 656598f

Please sign in to comment.