Skip to content

Instantly share code, notes, and snippets.

@sudarshansb143
Created March 30, 2024 04:30
Show Gist options
  • Select an option

  • Save sudarshansb143/91d4fefa3ee53578ac43e3b54f025731 to your computer and use it in GitHub Desktop.

Select an option

Save sudarshansb143/91d4fefa3ee53578ac43e3b54f025731 to your computer and use it in GitHub Desktop.
public List<TokenDateDistributionDto> splitAndProcess(List<TokenDateDistributionDto> dataList) {
// Get the size of the data list
int dataSize = dataList.size();
// Determine the number of parts based on the size of the data list
int numParts;
// Choose the number of parts based on the size of the data list
if (dataSize > 21 && dataSize < 180) {
numParts = dataSize / 7; // If the size is between 21 and 180, split into 7 parts
} else if (dataSize >= 180 && dataSize < 1000) {
numParts = dataSize / 30; // If the size is between 180 and 1000, split into 30 parts
} else if (dataSize >=1000) {
numParts = dataSize / 360; // If the size is 1000 or more, split into 360 parts
} else {
return dataList; // Return the original data list if none of the conditions are met
}
// Calculate the size of each part
int partSize = dataSize / numParts;
if (dataSize % numParts != 0) {
partSize++; // Adjust for remainder
}
// Create a list to store the processed data
List<TokenDateDistributionDto> processedList = new ArrayList<>();
// Process each part
for (int i = 0; i < dataSize; i += partSize) {
int endIndex = Math.min(i + partSize, dataSize);
List<TokenDateDistributionDto> part = dataList.subList(i, endIndex);
// Concatenate dates and sum total counts for the part
String startDate = part.get(0).getDate();
String endDate = part.get(part.size() - 1).getDate();
int totalTokens = 0;
for (TokenDateDistributionDto dto : part) {
totalTokens += dto.getTotalCount();
}
// Create a new TokenDateDistributionDto object for the processed part
processedList.add(new TokenDateDistributionDto(startDate + " - " + endDate, totalTokens));
}
// Return the processed data list
return processedList;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment