-
Notifications
You must be signed in to change notification settings - Fork 3.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
f99d48d
commit 05562cc
Showing
1 changed file
with
52 additions
and
0 deletions.
There are no files selected for viewing
52 changes: 52 additions & 0 deletions
52
src/client/java/teammates/client/scripts/ListActiveInstructors.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |