Skip to content

Commit

Permalink
[#10928] Add script to list active instructors within a period (#10947)
Browse files Browse the repository at this point in the history
* Add script to list active instructors

* Change date input format to human-readable version

* Change from ArrayList to Set

* Enhance the script with binary search

* Replace full load with filter load

* Rectify filter field
  • Loading branch information
daongochieu2810 authored Feb 15, 2021
1 parent f99d48d commit 05562cc
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package teammates.client.scripts;

import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneOffset;
import java.util.HashSet;
import java.util.Set;

import teammates.client.remoteapi.RemoteApiClient;
import teammates.storage.entity.FeedbackSession;

/**
* Script to generate emails of active instructors within a period.
*/
public class ListActiveInstructors extends RemoteApiClient {
@Override
protected void doOperation() {
//2010/01/01
int startDate = 1;
int startMonth = 1;
int startYear = 2010;
//2021/02/01
int endDate = 1;
int endMonth = 3;
int endYear = 2021;

LocalDate startPoint = LocalDate.of(startYear, startMonth, startDate);
LocalDate endPoint = LocalDate.of(endYear, endMonth, endDate);
long startTimeInMilli = startPoint.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli();
long endTimeInMilli = endPoint.atStartOfDay().toInstant(ZoneOffset.UTC).toEpochMilli();
Instant startTime = Instant.ofEpochMilli(startTimeInMilli);
Instant endTime = Instant.ofEpochMilli(endTimeInMilli);

Set<String> activeInstructorEmails = new HashSet<>();

ofy().load().type(FeedbackSession.class)
.filter("startTime >=", startTime)
.filter("startTime <=", endTime).project().forEach(feedbackSession -> {
activeInstructorEmails.add(feedbackSession.getCreatorEmail());
});

StringBuilder results = new StringBuilder();
for (String email : activeInstructorEmails) {
results.append(email).append(", \n");
}
System.out.println(results.toString());
}

public static void main(String[] args) throws Exception {
new ListActiveInstructors().doOperationRemotely();
}
}

0 comments on commit 05562cc

Please sign in to comment.