fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.security.MessageDigest;
  4. import java.security.NoSuchAlgorithmException;
  5.  
  6. class SSE2CohortPredictor {
  7.  
  8. private static final double UNSIGNED_16_MAX = Math.pow(2, 16);
  9. private static final String COHORT_SALT = "ADVANCE_PAYMENT_COHORT_OPEN_RATE";
  10. private static final String SSE2_SALT = "SUPER_SAVER_EMI_2";
  11.  
  12. public static void main(String[] args) {
  13. // ========== QA: CHANGE THESE VALUES ==========
  14. String loanId = "69125";
  15. int cohortOpenRate = 10; // CMS: ADVANCE_PAYMENT_COHORT_OPEN_RATE
  16. int sse2OpenRate = 50; // CMS: SSE_V2_OPEN_RATE
  17. // =============================================
  18.  
  19. double cohortSplit = getSplit(COHORT_SALT, loanId);
  20. boolean isTestGroup = cohortSplit < (cohortOpenRate / 100.0);
  21.  
  22. System.out.println("============================================================");
  23. System.out.println("Loan ID : " + loanId);
  24. System.out.println("Cohort Split : " + cohortSplit);
  25. System.out.println("Cohort Open Rate : " + cohortOpenRate + "%");
  26. System.out.println("Cohort Group : " + (isTestGroup ? "TEST" : "CONTROL"));
  27. System.out.println("============================================================");
  28.  
  29. if (!isTestGroup) {
  30. System.out.println("Result : SSE1 (COHORT CONTROL group)");
  31. return;
  32. }
  33.  
  34. double sse2Split = getSplit(SSE2_SALT, loanId);
  35. boolean isSse2 = sse2Split < (sse2OpenRate / 100.0);
  36.  
  37. System.out.println("SSE2 Split : " + sse2Split);
  38. System.out.println("SSE2 Open Rate : " + sse2OpenRate + "%");
  39. System.out.println("SSE2 Eligible : " + (isSse2 ? "YES" : "NO"));
  40. System.out.println("Result : " + (isSse2 ? "SSE2" : "SSE1 (TEST but not SSE2 eligible)"));
  41. }
  42.  
  43. private static double getSplit(String salt, String uniqueId) {
  44. try {
  45. byte[] hash = MessageDigest.getInstance("SHA-256").digest((uniqueId + salt).getBytes());
  46. int value = ((hash[0] & 0xFF) << 8) | (hash[1] & 0xFF);
  47. return value / UNSIGNED_16_MAX;
  48. throw new RuntimeException(e);
  49. }
  50. }
  51. }
Success #stdin #stdout 0.16s 60432KB
stdin
Standard input is empty
stdout
============================================================
Loan ID          : 69125
Cohort Split     : 0.71502685546875
Cohort Open Rate : 10%
Cohort Group     : CONTROL
============================================================
Result           : SSE1 (COHORT CONTROL group)