Skip to content
This repository was archived by the owner on Jan 23, 2025. It is now read-only.

Commit dc43b81

Browse files
committed
Challenge receipt update - estimation and actual listed in same table
1 parent 5523c8b commit dc43b81

File tree

6 files changed

+525
-513
lines changed

6 files changed

+525
-513
lines changed

src/java/main/com/topcoder/direct/services/view/dto/contest/ContestReceiptDTO.java

Lines changed: 143 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
package com.topcoder.direct.services.view.dto.contest;
55

66
import com.topcoder.direct.services.view.dto.cost.CostDTO;
7+
import com.topcoder.management.project.Prize;
78

89
import java.io.Serializable;
10+
import java.util.ArrayList;
11+
import java.util.Collections;
12+
import java.util.Comparator;
13+
import java.util.HashMap;
914
import java.util.List;
15+
import java.util.Map;
1016

1117
/**
1218
* <p>A DTO providing the complete details on a contest receipt.</p>
@@ -35,8 +41,17 @@
3541
* </ul>
3642
* </p>
3743
*
44+
* <p>
45+
* Version 1.5 ([Direct] - challenge receipt page update)
46+
* <ul>
47+
* <li>Added {@link #getWinnerEntries()}</li>
48+
* <li>Added {@link #getCheckpointWinnerEntries()}</li>
49+
* <li>Added {@link #getNonWinnerEntries()}</li>
50+
* </ul>
51+
* </p>
52+
*
3853
* @author flexme, GreatKevin, Veve
39-
* @version 1.4
54+
* @version 1.5
4055
*/
4156
public class ContestReceiptDTO implements Serializable {
4257
/**
@@ -500,6 +515,133 @@ public void setEntries(List<ContestReceiptEntry> entries) {
500515
this.entries = entries;
501516
}
502517

518+
/**
519+
* Gets the winner entries.
520+
*
521+
* @return the list of winner entries.
522+
* @since 1.5
523+
*/
524+
public List<ContestReceiptEntry> getWinnerEntries() {
525+
List<ContestReceiptEntry> winnerEntries = new ArrayList<ContestReceiptEntry>();
526+
527+
for (ContestReceiptEntry e : this.getEntries()) {
528+
529+
if (e.getPaymentType().equalsIgnoreCase("winner")) {
530+
winnerEntries.add(e);
531+
}
532+
}
533+
534+
Collections.sort(winnerEntries, new Comparator<ContestReceiptEntry>() {
535+
public int compare(ContestReceiptEntry o1, ContestReceiptEntry o2) {
536+
return Double.compare(o2.getPaymentAmount(), o1.getPaymentAmount());
537+
}
538+
});
539+
540+
// get the main winner prizes
541+
List<Prize> prizes = getEstimation().getMainPrizes();
542+
543+
int prizeRank = 1;
544+
545+
int maxPrizePlace = -1;
546+
547+
for (ContestReceiptEntry e : winnerEntries) {
548+
for (Prize p : prizes) {
549+
550+
if (p.getPlace() > maxPrizePlace) {
551+
maxPrizePlace = p.getPlace();
552+
}
553+
554+
if (p.getPlace() == prizeRank ) {
555+
e.setEstimatedAmount(p.getPrizeAmount());
556+
}
557+
}
558+
prizeRank++;
559+
}
560+
561+
if (maxPrizePlace > winnerEntries.size()) {
562+
for (int k = winnerEntries.size(); k < maxPrizePlace; ++k) {
563+
ContestReceiptEntry extraEntry = new ContestReceiptEntry();
564+
extraEntry.setPaymentType("Winner");
565+
extraEntry.setEstimatedAmount(prizes.get(k).getPrizeAmount());
566+
winnerEntries.add(extraEntry);
567+
}
568+
}
569+
570+
return winnerEntries;
571+
}
572+
573+
/**
574+
* Gets the checkpoint winner entries.
575+
*
576+
* @return the checkpoint winner entries.
577+
* @since 1.5
578+
*/
579+
public List<ContestReceiptEntry> getCheckpointWinnerEntries() {
580+
List<ContestReceiptEntry> checkpointWinnerEntries = new ArrayList<ContestReceiptEntry>();
581+
582+
// get the checkpoint prize
583+
Prize checkpointPrize = this.getEstimation().getCheckpointPrize();
584+
585+
if (checkpointPrize == null) {
586+
return checkpointWinnerEntries;
587+
}
588+
589+
for (ContestReceiptEntry e : this.getEntries()) {
590+
if(e.getPaymentType().equalsIgnoreCase("checkpoint winner")) {
591+
checkpointWinnerEntries.add(e);
592+
}
593+
}
594+
595+
Collections.sort(checkpointWinnerEntries, new Comparator<ContestReceiptEntry>() {
596+
public int compare(ContestReceiptEntry o1, ContestReceiptEntry o2) {
597+
return Double.compare(o2.getPaymentAmount(), o1.getPaymentAmount());
598+
}
599+
});
600+
601+
for (ContestReceiptEntry e : checkpointWinnerEntries) {
602+
e.setEstimatedAmount(checkpointPrize.getPrizeAmount());
603+
}
604+
605+
if (checkpointPrize.getNumberOfSubmissions() > checkpointWinnerEntries.size()) {
606+
for (int k = checkpointWinnerEntries.size(); k < checkpointPrize.getNumberOfSubmissions(); ++k) {
607+
ContestReceiptEntry extraEntry = new ContestReceiptEntry();
608+
extraEntry.setPaymentType("Checkpoint Winner");
609+
extraEntry.setEstimatedAmount(checkpointPrize.getPrizeAmount());
610+
checkpointWinnerEntries.add(extraEntry);
611+
}
612+
}
613+
614+
return checkpointWinnerEntries;
615+
}
616+
617+
/**
618+
* Gets the nonWinner (checkpoint winner) entries.
619+
*
620+
* @return the list of nonWinner (checkpint winner) entries.
621+
* @since 1.5
622+
*/
623+
public Map<String, ContestReceiptEntry> getNonWinnerEntries() {
624+
// map which is used to aggregate the payment amount of the same payment type
625+
Map<String, ContestReceiptEntry> entriesMap = new HashMap<String, ContestReceiptEntry>();
626+
627+
for (ContestReceiptEntry e : this.getEntries()) {
628+
if (!(e.getPaymentType().equalsIgnoreCase("winner")
629+
|| e.getPaymentType().equalsIgnoreCase("checkpoint winner"))) {
630+
if (entriesMap.containsKey(e.getPaymentType())) {
631+
// exists, sum up the payment amount
632+
ContestReceiptEntry existingEntry = entriesMap.get(e.getPaymentType());
633+
existingEntry.setPaymentAmount(existingEntry.getPaymentAmount() + e.getPaymentAmount());
634+
} else {
635+
// no exist, put into map
636+
entriesMap.put(e.getPaymentType(), new ContestReceiptEntry(e));
637+
}
638+
}
639+
}
640+
641+
return entriesMap;
642+
}
643+
644+
503645
/**
504646
* Gets the estimation cost.
505647
*

src/java/main/com/topcoder/direct/services/view/dto/contest/ContestReceiptEntry.java

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
11
/*
2-
* Copyright (C) 2012 TopCoder Inc., All Rights Reserved.
2+
* Copyright (C) 2012 - 2014 TopCoder Inc., All Rights Reserved.
33
*/
44
package com.topcoder.direct.services.view.dto.contest;
55

66
/**
77
* Represents a record entry in the contest receipt
88
*
9-
* @author GreatKevin
10-
* @version 1.0
9+
* <p>
10+
* Version 1.1 ([Direct] - challenge receipt page update)
11+
* <ul>
12+
* <li>Added {@link #paymentTypeId} and its getter and setter</li>
13+
* <li>Added {@link #estimatedAmount} and its getter and setter</li>
14+
* <li>Added default constructor {@link #ContestReceiptEntry()}</li>
15+
* <li>Added copy constructor {@link #ContestReceiptEntry(ContestReceiptEntry)}</li>
16+
* </ul>
17+
* </p>
18+
*
19+
* @author GreatKevin, Veve
20+
* @version 1.1
1121
*/
1222
public class ContestReceiptEntry {
1323

@@ -21,6 +31,40 @@ public class ContestReceiptEntry {
2131
*/
2232
private double paymentAmount;
2333

34+
/**
35+
* The payment type id.
36+
* @since 1.1
37+
*/
38+
private long paymentTypeId;
39+
40+
/**
41+
* The estimation cost amount of this payment type.
42+
* @since 1.1
43+
*/
44+
private double estimatedAmount;
45+
46+
/**
47+
* The default constructor.
48+
*
49+
* @since 1.1
50+
*/
51+
public ContestReceiptEntry() {
52+
53+
}
54+
55+
/**
56+
* The copy constructor.
57+
*
58+
* @param entry the entry to copy.
59+
* @since 1.1
60+
*/
61+
public ContestReceiptEntry(ContestReceiptEntry entry) {
62+
this.paymentType = entry.getPaymentType();
63+
this.paymentAmount = entry.getPaymentAmount();
64+
this.paymentTypeId = entry.getPaymentTypeId();
65+
this.estimatedAmount = entry.getEstimatedAmount();
66+
}
67+
2468
/**
2569
* Gets the payment type.
2670
*
@@ -56,4 +100,44 @@ public double getPaymentAmount() {
56100
public void setPaymentAmount(double paymentAmount) {
57101
this.paymentAmount = paymentAmount;
58102
}
103+
104+
/**
105+
* Gets the payment type id.
106+
*
107+
* @return the payment type id.
108+
* @since 1.1
109+
*/
110+
public long getPaymentTypeId() {
111+
return paymentTypeId;
112+
}
113+
114+
/**
115+
* Sets the payment type id.
116+
*
117+
* @param paymentTypeId the payment type id.
118+
* @since 1.1
119+
*/
120+
public void setPaymentTypeId(long paymentTypeId) {
121+
this.paymentTypeId = paymentTypeId;
122+
}
123+
124+
/**
125+
* Gets the estimated amount.
126+
*
127+
* @return the estimated amount.
128+
* @since 1.1
129+
*/
130+
public double getEstimatedAmount() {
131+
return estimatedAmount;
132+
}
133+
134+
/**
135+
* Sets the estimated amount.
136+
*
137+
* @param estimatedAmount the estimated amount.
138+
* @since 1.1
139+
*/
140+
public void setEstimatedAmount(double estimatedAmount) {
141+
this.estimatedAmount = estimatedAmount;
142+
}
59143
}

0 commit comments

Comments
 (0)