Skip to content

Commit

Permalink
Add creating projects
Browse files Browse the repository at this point in the history
  • Loading branch information
Anatoly Anischenko committed Dec 1, 2020
1 parent d46066c commit 506e1d2
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 22 deletions.
59 changes: 56 additions & 3 deletions src/generator/Generator.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public class Generator {

private static final String HUGE_SCRIPT_SEPARATOR = "\n------------------------------------------\n";
private static final String SCRIPT_SEPARATOR = "\n---------------------\n";
private static final String SMALL_SCRIPT_SEPARATOR = "---------------------\n";
private static final String SMALL_SCRIPT_SEPARATOR = "---------------------";

private static final int COUNT_OF_PEOPLE = 1000;
private static final int COUNT_OF_PARTICIPANTS = 300;
Expand Down Expand Up @@ -189,9 +189,32 @@ public static void main(String[] args) throws FileNotFoundException {
Team.generate(new ArrayList<>(teammates), new ArrayList<>(curMentors), championship.championship_id);
}

//project
addScript(SMALL_SCRIPT_SEPARATOR);

//generate judgeTeams
while (judges_id.size() != used_judges_id.size()) {
Set<Integer> curJudges = new HashSet<>();
while (curJudges.size() < 3) {
int curJudge = selectRandomJudge();
curJudges.add(curJudge);
used_judges_id.add(curJudge);
}

JudgeTeam.generate(new ArrayList<>(curJudges), championship.championship_id);
}

addScript(SMALL_SCRIPT_SEPARATOR);

//generate projects
for (Team team : teams) {
Project.generate(team.team_id, getRandomSublist(championship.cases));

//judgeTeam
while (random.nextInt(10) > 6) {
Project.generate(team.team_id, getRandomSublist(championship.cases));
}
}

addScript(SMALL_SCRIPT_SEPARATOR);

//performance

Expand Down Expand Up @@ -288,6 +311,22 @@ private static int selectRandomMentor() {
}
}

private static int selectRandomJudge() {
while (true) {
int size = judges_id.size();
int item = random.nextInt(size);
int i = 0;

for (int obj : judges_id) {
if (i == item && !used_judges_id.contains(obj)) {
return obj;
}

i++;
}
}
}

private static int selectRandomPersonWithPublication() {
while (true) {
int size = peopleWithPublication.size();
Expand Down Expand Up @@ -336,4 +375,18 @@ public static int age(LocalDate birthDate) {
return 0;
}
}

public static <T> ArrayList<T> getRandomSublist(ArrayList<T> input) {
ArrayList<T> result = new ArrayList<>();

while (result.isEmpty()) {
for (T element : input) {
if (random.nextInt(10) > 3) {
result.add(element);
}
}
}

return result;
}
}
32 changes: 32 additions & 0 deletions src/generator/objects/JudgeTeam.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,36 @@
package generator.objects;

import generator.Generator;

import java.util.ArrayList;

public class JudgeTeam {
private static int cnt = 1;

private static final String INSERT_SCRIPT_TEMPLATE = "SELECT insert_judge_team('%s', %d);";

public int judge_team_id;
public ArrayList<Integer> judges;
public int championship_id;

private JudgeTeam(ArrayList<Integer> judges, int championship_id) {
this.judge_team_id = cnt++;
this.judges = judges;
this.championship_id = championship_id;
}

public static JudgeTeam generate(ArrayList<Integer> judges, int championship_id) {
return insert(judges, championship_id);
}

public static JudgeTeam insert(ArrayList<Integer> judges, int championship_id) {
Generator.addScript(String.format(INSERT_SCRIPT_TEMPLATE,
Generator.getIntArray(judges),
championship_id));

JudgeTeam newJudgeTeam = new JudgeTeam(judges, championship_id);
Generator.judgeTeams.add(newJudgeTeam);

return newJudgeTeam;
}
}
31 changes: 12 additions & 19 deletions src/generator/objects/Project.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,51 +2,44 @@

import generator.Generator;

//fixme я не знаю как передавать массив кейсов и соответственно его выводить
import java.util.ArrayList;

public class Project {
private static int cnt = 1;

private static final String INSERT_SCRIPT_TEMPLATE = "SELECT insert_project('%s', %d, '%s', '%s');";
private static final String PROJECT_NAME_TEMPLATE = "Project %d";
private static final String PROJECT_DESCRIPTION_TEMPLATE = "Description for \"%s\"";

public int project_id;
public String name;
public int team_id;
public ArrayList<Integer> cases;
public String description;

private Project(String name, int team_id, String description) {
private Project(String name, int team_id, ArrayList<Integer> cases, String description) {
this.project_id = cnt++;
this.name = name;
this.team_id = team_id;
this.cases = cases;
this.description = description;
}

public static Project generate() {
String title = generateProject();
int _cases = 1;
return insert(title, cnt, _cases, "The best project ever");
public static Project generate(int team_id, ArrayList<Integer> cases) {
String name = generateProjectName();
return insert(name, team_id, cases, String.format(PROJECT_DESCRIPTION_TEMPLATE, name));
}

public static Project generate(int team_id, int _cases) {
String title = generateProject();
return insert(title, team_id, _cases, String.format(PROJECT_NAME_TEMPLATE, cnt));
}

public static Project insert(String name, int team_id, int _cases, String description) {
Generator.addScript(String.format(INSERT_SCRIPT_TEMPLATE, name, team_id,_cases,description));
public static Project insert(String name, int team_id, ArrayList<Integer> cases, String description) {
Generator.addScript(String.format(INSERT_SCRIPT_TEMPLATE, name, team_id, Generator.getIntArray(cases), description));

Project newProject = new Project(name,team_id, description);
Project newProject = new Project(name, team_id, cases, description);
Generator.projects.add(newProject);

return newProject;
}

public static String generateProject() {
return generateProject("simple_project");
}

public static String generateProject(String name) {
public static String generateProjectName() {
return String.format(PROJECT_NAME_TEMPLATE, cnt);
}
}

0 comments on commit 506e1d2

Please sign in to comment.