Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4063160133 | ||
|
|
427267c4bf | ||
|
|
82b9ae15d9 | ||
|
|
29e4096e95 | ||
|
|
1d2c04d95c | ||
|
|
29956d0b92 | ||
|
|
d7cb3c0e8e |
+4
-4
@@ -1,11 +1,11 @@
|
|||||||
package SuMoC.backend.gamification.badges;
|
package SuMoC.backend.seed;
|
||||||
|
|
||||||
|
import SuMoC.backend.gamification.badges.BadgeRepository;
|
||||||
|
import SuMoC.backend.gamification.badges.BadgeService;
|
||||||
import SuMoC.backend.gamification.badges.mapper.BadgeMapper;
|
import SuMoC.backend.gamification.badges.mapper.BadgeMapper;
|
||||||
import SuMoC.backend.gamification.badges.models.Badge;
|
|
||||||
import SuMoC.backend.gamification.badges.models.BadgeCategory;
|
import SuMoC.backend.gamification.badges.models.BadgeCategory;
|
||||||
import SuMoC.backend.gamification.badges.models.BadgeDTO;
|
import SuMoC.backend.gamification.badges.models.BadgeDTO;
|
||||||
import jakarta.transaction.Transactional;
|
import jakarta.transaction.Transactional;
|
||||||
import kotlin.collections.ArrayDeque;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.CommandLineRunner;
|
import org.springframework.boot.CommandLineRunner;
|
||||||
import org.springframework.context.annotation.Profile;
|
import org.springframework.context.annotation.Profile;
|
||||||
@@ -16,7 +16,7 @@ import java.util.*;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Profile("dev")
|
@Profile("dev")
|
||||||
@Order(3)
|
@Order(2)
|
||||||
public class DevBadgeSeeder implements CommandLineRunner {
|
public class DevBadgeSeeder implements CommandLineRunner {
|
||||||
|
|
||||||
private final BadgeService badgeService;
|
private final BadgeService badgeService;
|
||||||
@@ -16,7 +16,7 @@ import java.util.*;
|
|||||||
|
|
||||||
@Component
|
@Component
|
||||||
@Profile("dev")
|
@Profile("dev")
|
||||||
@Order(4)
|
@Order(3)
|
||||||
public class DevChallengeSeeder implements CommandLineRunner {
|
public class DevChallengeSeeder implements CommandLineRunner {
|
||||||
|
|
||||||
private final ChallengeService challengeService;
|
private final ChallengeService challengeService;
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
package SuMoC.backend.seed.trip;
|
|
||||||
|
|
||||||
import SuMoC.backend.trip.TripFactory;
|
|
||||||
import SuMoC.backend.trip.TripService;
|
|
||||||
import SuMoC.backend.trip.dtos.NewTripDTO;
|
|
||||||
import SuMoC.backend.user.repository.UserRepository;
|
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
|
||||||
import org.springframework.boot.CommandLineRunner;
|
|
||||||
import org.springframework.context.annotation.Profile;
|
|
||||||
import org.springframework.core.annotation.Order;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
@Component
|
|
||||||
@Profile("dev")
|
|
||||||
@Order(2)
|
|
||||||
public class DevTripSeeder implements CommandLineRunner {
|
|
||||||
|
|
||||||
private final TripService tripService;
|
|
||||||
|
|
||||||
private final UserRepository userRepository;
|
|
||||||
|
|
||||||
|
|
||||||
@Autowired
|
|
||||||
public DevTripSeeder(TripService tripService, UserRepository userRepository) {
|
|
||||||
this.tripService = tripService;
|
|
||||||
this.userRepository = userRepository;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run(String... args) throws Exception {
|
|
||||||
// Iterate over all users and create 5 random trips for each of the last 5 weeks + adds car trips for every day at same time
|
|
||||||
userRepository.findAll().forEach(user -> {
|
|
||||||
for (int week = 0; week < 5; week++) {
|
|
||||||
for (int day = 0; day < 7; day++) {
|
|
||||||
// NewTripDTO carTrip = TripFactory.newCarTripDTO(
|
|
||||||
// Instant.now()
|
|
||||||
// .minus(Duration.ofDays(week * 7 + day)).atZone(ZoneId.systemDefault()).toInstant()
|
|
||||||
// );
|
|
||||||
// This should definitly trigger regularTripDetection
|
|
||||||
NewTripDTO triggerCarTrip = TripFactory.newTriggeringCarMock(
|
|
||||||
java.time.Instant.now().minus(java.time.Duration.ofDays(week * 7 + day))
|
|
||||||
);
|
|
||||||
tripService.addTrip(user, triggerCarTrip);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Create 5 trips per week
|
|
||||||
// for (int i = 0; i < 5; i++) {
|
|
||||||
// // Create trips within each week's time range
|
|
||||||
// long daysAgo = week * 7 + (long) (Math.random() * 7);
|
|
||||||
// NewTripDTO newTrip = TripFactory.randomNewTripDTO(
|
|
||||||
// java.time.Instant.now().minus(java.time.Duration.ofDays((long) (Math.random() * 30))));
|
|
||||||
// tripService.addTrip(user, newTrip);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -45,11 +45,11 @@ public class DevUserSeeder implements CommandLineRunner {
|
|||||||
|
|
||||||
Long positionIndex = 1L;
|
Long positionIndex = 1L;
|
||||||
for (var user : pgMembers) {
|
for (var user : pgMembers) {
|
||||||
addDummyStats(user, positionIndex);
|
addDummyStats(user);
|
||||||
positionIndex++;
|
positionIndex++;
|
||||||
}
|
}
|
||||||
for (var user : defaultTestUsers) {
|
for (var user : defaultTestUsers) {
|
||||||
addDummyStats(user, positionIndex);
|
addDummyStats(user);
|
||||||
positionIndex++;
|
positionIndex++;
|
||||||
}
|
}
|
||||||
//List<User> nTestUsers = seedNtestUsers(10);
|
//List<User> nTestUsers = seedNtestUsers(10);
|
||||||
@@ -261,31 +261,31 @@ public class DevUserSeeder implements CommandLineRunner {
|
|||||||
return createdUsers;
|
return createdUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addDummyStats(User user, Long positionIndex) {
|
private void addDummyStats(User user) {
|
||||||
user.getStats().addToStat(
|
user.getStats().addToStat(
|
||||||
Timeframe.WEEKLY,
|
Timeframe.WEEKLY,
|
||||||
"XP",
|
"XP",
|
||||||
100L * positionIndex
|
0
|
||||||
);
|
);
|
||||||
user.getStats().addToStat(
|
user.getStats().addToStat(
|
||||||
Timeframe.WEEKLY,
|
Timeframe.WEEKLY,
|
||||||
"CO2_SAVED",
|
"CO2_SAVED",
|
||||||
500L * positionIndex
|
0
|
||||||
);
|
);
|
||||||
user.getStats().addToStat(
|
user.getStats().addToStat(
|
||||||
Timeframe.WEEKLY,
|
Timeframe.WEEKLY,
|
||||||
"KM_CYCLED",
|
"KM_CYCLED",
|
||||||
20L * positionIndex
|
0
|
||||||
);
|
);
|
||||||
user.getStats().addToStat(
|
user.getStats().addToStat(
|
||||||
Timeframe.WEEKLY,
|
Timeframe.WEEKLY,
|
||||||
"KM_WALKED",
|
"KM_WALKED",
|
||||||
10L * positionIndex
|
0
|
||||||
);
|
);
|
||||||
user.getStats().addToStat(
|
user.getStats().addToStat(
|
||||||
Timeframe.WEEKLY,
|
Timeframe.WEEKLY,
|
||||||
"KM_PUBLIC_TRANSPORT",
|
"KM_PUBLIC_TRANSPORT",
|
||||||
15L * positionIndex
|
0
|
||||||
);
|
);
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 130 KiB After Width: | Height: | Size: 2.4 MiB |
Reference in New Issue
Block a user