Skip to content

Commit

Permalink
Add tool for updating the conference ranks.
Browse files Browse the repository at this point in the history
Signed-off-by: Stéphane Galland <galland@arakhne.org>
  • Loading branch information
gallandarakhneorg committed May 18, 2024
1 parent 5e87591 commit ee29af2
Show file tree
Hide file tree
Showing 7 changed files with 837 additions and 1 deletion.
1 change: 0 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
* projects
* publications
* members
* Update conference rankings
* Merge similar entities
* Persons
* organizations
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
package fr.utbm.ciad.labmanager.services.conference;

import java.io.IOException;
import java.io.Serializable;
import java.net.URL;
import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -114,6 +115,20 @@ public List<Conference> getAllConferences() {
return this.conferenceRepository.findAll();
}

/** Replies all the conferences for the database.
*
* @return the list of conferences.
* @param callback is invoked on each entity in the context of the JPA session. It may be used for forcing the loading of some lazy-loaded data.
* @since 4.0
*/
public List<Conference> getAllConferences(Consumer<Conference> callback) {
final var list = this.conferenceRepository.findAll();
if (callback != null) {
list.forEach(callback);
}
return list;
}

/** Replies all the conferences for the database.
*
* @param filter the filter of conferences.
Expand All @@ -124,6 +139,21 @@ public List<Conference> getAllConferences(Specification<Conference> filter) {
return this.conferenceRepository.findAll(filter);
}

/** Replies all the conferences for the database.
*
* @param filter the filter of conferences.
* @param callback is invoked on each entity in the context of the JPA session. It may be used for forcing the loading of some lazy-loaded data.
* @return the list of conferences.
* @since 4.0
*/
public List<Conference> getAllConferences(Specification<Conference> filter, Consumer<Conference> callback) {
final var list = this.conferenceRepository.findAll(filter);
if (callback != null) {
list.forEach(callback);
}
return list;
}

/** Replies all the conferences for the database.
*
* @param filter the filter of conferences.
Expand Down Expand Up @@ -438,6 +468,31 @@ private void readCorePortalIndicators(Session session, int year, Conference conf
session.getTransaction().commit();
}

/** Update the conference indicators according to the given inputs.
*
* @param referenceYear the reference year.
* @param conferenceUpdates the streams that describes the updates.
* @param progress the progression monitor.
* @throws Exception if the journal information cannot be downloaded.
* @since 4.0
*/
@Transactional
public void updateConferenceIndicators(int referenceYear, Collection<ConferenceRankingUpdateInformation> conferenceUpdates, Progression progress) {
progress.setProperties(0, 0, conferenceUpdates.size() + 1, false);
final var conferences = new ArrayList<Conference>();
conferenceUpdates.forEach(info -> {
final var conference = info.conference();
progress.setComment(conference.getAcronymAndName());
if (info.ranking() != null) {
conference.setCoreIndexByYear(referenceYear, info.ranking());
}
conferences.add(conference);
progress.increment();
});
this.conferenceRepository.saveAll(conferences);
progress.end();
}

/** Save conference indicators. If a conference is not mentioned in the given map, its associated indicators will be not changed.
*
* @param year the reference year.
Expand All @@ -460,6 +515,43 @@ public void updateConferenceIndicators(int year, Map<Long, CoreRanking> changes)
}
}

/** Download the conference indicators for the given reference year for the CORE portail.
* This function uses the {@link CorePortalPlatform} tool for downloading indicators.
*
* @param referenceYear the reference year.
* @param conferences the list of conferences for which the indicators should be downloaded.
* @param progress the progression monitor.
* @param consumer the consumer of the conference ranking information.
* @throws Exception if the conference information cannot be downloaded.
* @since 4.0
*/
@Transactional(readOnly = true)
public void downloadConferenceIndicatorsFromCore(int referenceYear, List<Conference> conferences, Progression progress, ConferenceRankingConsumer consumer) throws Exception {
final var progress0 = progress == null ? new DefaultProgression() : progress;
progress0.setProperties(0, 0, conferences.size() * 2, false);
for (final var conference : conferences) {
progress0.setComment(conference.getAcronymAndName());
if (!Strings.isNullOrEmpty(conference.getCoreId())) {
final var lastRanking = conference.getCoreIndexByYear(referenceYear);
final var rankings = this.corePortal.getConferenceRanking(referenceYear, conference.getCoreId(), progress0.subTask(1));
progress0.ensureNoSubTask();
if (rankings != null) {
if (rankings.ranking == null) {
consumer.consume(referenceYear, conference.getId(), lastRanking, CoreRanking.NR);
} else {
consumer.consume(referenceYear, conference.getId(), lastRanking, rankings.ranking);
}
} else {
consumer.consume(referenceYear, conference.getId(), lastRanking, CoreRanking.NR);
}
progress0.increment();
} else {
progress0.subTask(2);
}
}
progress0.end();
}

@Override
public EntityEditingContext<Conference> startEditing(Conference conference) {
assert conference != null;
Expand Down Expand Up @@ -572,4 +664,39 @@ protected void deleteEntities(Collection<Long> identifiers) throws Exception {

}

/** Consumer of conference ranking information with ranking scores.
*
* @author $Author: sgalland$
* @version $Name$ $Revision$ $Date$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 4.0
*/
public interface ConferenceRankingConsumer extends Serializable {

/** Invoked when a conference ranking is discovered from the source.
*
* @param referenceYear the reference year.
* @param conferenceId the identifier of the conference.
* @param oldRanking the previously know ranking.
* @param newRanking the current ranking.
*/
void consume(int referenceYear, long conferenceId, CoreRanking oldRanking, CoreRanking newRanking);

}

/** Description of the information for a conference.
*
* @param conference the conference.
* @param ranking the new CORE ranking, or {@code null} to avoid ranking change.
* @author $Author: sgalland$
* @version $Name$ $Revision$ $Date$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 4.0
*/
public record ConferenceRankingUpdateInformation(Conference conference, CoreRanking ranking) {
//
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
/*
* $Id$
*
* Copyright (c) 2019-2024, CIAD Laboratory, Universite de Technologie de Belfort Montbeliard
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

package fr.utbm.ciad.labmanager.views.appviews.conferences;

import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Stream;

import fr.utbm.ciad.labmanager.data.conference.Conference;
import fr.utbm.ciad.labmanager.utils.ranking.CoreRanking;
import fr.utbm.ciad.labmanager.views.components.addons.wizard.AbstractContextData;

/** Data in the wizard for updating the conference ranking.
*
* @author $Author: sgalland$
* @version $Name$ $Revision$ $Date$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 4.0
*/
public class ConferenceRankingUpdate extends AbstractContextData {

private static final long serialVersionUID = 1506566568548752541L;

private int year = LocalDate.now().getYear() - 1;

private List<Conference> conferences = new ArrayList<>();

private final Map<Long, ConferenceRankingInformation> core = new TreeMap<>();

/** Constructor.
*/
public ConferenceRankingUpdate() {
//
}

/** Replies the year for the ranking updates.
*
* @return the year.
*/
public synchronized int getYear() {
return this.year;
}

/** Set the year for the ranking updates.
*
* @param year the year.
*/
public synchronized void setYear(int year) {
this.year = year;
}

/** Replies the list of conferences.
*
* @return the conferences.
*/
public synchronized List<Conference> getConferences() {
return this.conferences;
}

/** Change the list of conferences.
*
* @param conferences the conferences.
*/
public synchronized void setConferences(List<Conference> conferences) {
assert conferences != null;
this.conferences = conferences;
}

/** Remove all the references to the Worankings.
*/
public synchronized void clearRankings() {
this.core.clear();
}

/** Add ranking for the conference with the given identifier.
*
* @param conferenceId the identifier of the conference.
* @param knownRanking the CORE ranking of the conference that is already known.
* @param newRanking the new CORE ranking for the conference.
*/
public synchronized void addRanking(long conferenceId, CoreRanking knownRanking, CoreRanking newRanking) {
this.core.put(Long.valueOf(conferenceId), new ConferenceRankingInformation(knownRanking, newRanking));
}

/** Replies all the update information about the conferences.
*
* @return the stream of information, one entry per conference.
*/
public Stream<ConferenceNewInformation> getConferenceUpdates() {
final var defaultRanking = new ConferenceRankingInformation(CoreRanking.NR, CoreRanking.NR);
return getConferences().stream().map(conference -> {
final var conferenceId = Long.valueOf(conference.getId());

final var core = this.core.getOrDefault(conferenceId, defaultRanking);
final var coreRanking = extractValue(core.knownRanking(), core.newRanking());

if (coreRanking != null) {
return new ConferenceNewInformation(conference,
extractKnownValue(core.knownRanking(), coreRanking), coreRanking);
}
return null;
}).filter(it -> it != null);
}

private static CoreRanking extractKnownValue(CoreRanking oldValue, CoreRanking newValue) {
if (newValue != null) {
return CoreRanking.normalize(oldValue);
}
return null;
}

private static CoreRanking extractValue(CoreRanking oldValue, CoreRanking newValue) {
final var ov = CoreRanking.normalize(oldValue);
final var nv = CoreRanking.normalize(newValue);
if (ov != nv) {
return newValue;
}
return null;
}

/** Description of the ranking information for a conference.
*
* @param knownRanking the ranking of the conference that is already known.
* @param newRanking the new ranking for the conference.
* @author $Author: sgalland$
* @version $Name$ $Revision$ $Date$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 4.0
*/
public record ConferenceRankingInformation(CoreRanking knownRanking, CoreRanking newRanking) {
//
}

/** Description of the information for a conference.
*
* @param conference the conference.
* @param oldRanking the old CORE ranking, or {@code null}.
* @param newRanking the ew CORE ranking, or {@code null}.
* @author $Author: sgalland$
* @version $Name$ $Revision$ $Date$
* @mavengroupid $GroupId$
* @mavenartifactid $ArtifactId$
* @since 4.0
*/
public record ConferenceNewInformation(Conference conference,
CoreRanking oldRanking, CoreRanking newRanking) {
//
}

}
Loading

0 comments on commit ee29af2

Please sign in to comment.