Skip to content

Commit

Permalink
Moving more types to prosper package (#52)
Browse files Browse the repository at this point in the history
* Moving more types to prosper package

* Renaming ProsperRating to Rating
  • Loading branch information
mtlynch committed Oct 6, 2016
1 parent 32918a3 commit c0f6a79
Show file tree
Hide file tree
Showing 21 changed files with 460 additions and 478 deletions.
87 changes: 43 additions & 44 deletions prosper/listing_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,69 +4,68 @@ import (
"fmt"

"github.com/mtlynch/gofn-prosper/prosper/thin"
"github.com/mtlynch/gofn-prosper/types"
)

type listingParser interface {
Parse(thin.SearchResult) (types.Listing, error)
Parse(thin.SearchResult) (Listing, error)
}

type defaultListingParser struct{}

func (p defaultListingParser) Parse(r thin.SearchResult) (types.Listing, error) {
func (p defaultListingParser) Parse(r thin.SearchResult) (Listing, error) {
incomeRange, err := parseIncomeRange(r.IncomeRange)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
listingStatus, err := parseListingStatus(r.ListingStatus)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
ficoScore, err := parseFicoScore(r.FicoScore)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
prosperRating, err := parseProsperRating(r.ProsperRating)
rating, err := parseRating(r.Rating)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
oldestTradeOpenDate, err := parseProsperOldTime(r.OldestTradeOpenDate)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
firstRecordedCreditLine, err := parseProsperTime(r.FirstRecordedCreditLine)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
creditPullDate, err := parseProsperTime(r.CreditPullDate)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
listingCreationDate, err := parseProsperTime(r.ListingCreationDate)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
listingEndDate, err := parseProsperTime(r.ListingEndDate)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
listingStartDate, err := parseProsperTime(r.ListingStartDate)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
wholeLoanStartDate, err := parseProsperTime(r.WholeLoanStartDate)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
wholeLoanEndDate, err := parseProsperTime(r.WholeLoanEndDate)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
lastUpdatedDate, err := parseProsperTime(r.LastUpdatedDate)
if err != nil {
return types.Listing{}, err
return Listing{}, err
}
return types.Listing{
return Listing{
PriorProsperLoans: r.PriorProsperLoans,
AmountDelinquent: r.AmountDelinquent,
AmountParticipation: r.AmountParticipation,
Expand All @@ -87,7 +86,7 @@ func (p defaultListingParser) Parse(r thin.SearchResult) (types.Listing, error)
IsHomeowner: r.IsHomeowner,
LastUpdatedDate: lastUpdatedDate,
ListingAmount: r.ListingAmount,
ListingNumber: types.ListingNumber(r.ListingNumber),
ListingNumber: ListingNumber(r.ListingNumber),
PriorProsperLoans61dpd: r.PriorProsperLoans61dpd,
PriorProsperLoansPrincipalBorrowed: r.PriorProsperLoansPrincipalBorrowed,
WasDelinquentDerog: r.WasDelinquentDerog,
Expand Down Expand Up @@ -117,7 +116,7 @@ func (p defaultListingParser) Parse(r thin.SearchResult) (types.Listing, error)
MonthlyDebt: r.MonthlyDebt,
MonthsEmployed: r.MonthsEmployed,
PartialFundingIndicator: r.PartialFundingIndicator,
ProsperRating: prosperRating,
Rating: rating,
ProsperScore: r.ProsperScore,
BorrowerApr: r.BorrowerApr,
PriorProsperLoans31dpd: r.PriorProsperLoans31dpd,
Expand Down Expand Up @@ -159,39 +158,39 @@ func (p defaultListingParser) Parse(r thin.SearchResult) (types.Listing, error)
}, nil
}

func parseIncomeRange(incomeRange int64) (types.IncomeRange, error) {
if incomeRange < int64(types.IncomeRangeMin) || incomeRange > int64(types.IncomeRangeMax) {
return types.IncomeRangeInvalid, fmt.Errorf("income range out of range: %d, expected %d-%d", incomeRange, types.IncomeRangeMin, types.IncomeRangeMax)
func parseIncomeRange(incomeRange int64) (IncomeRange, error) {
if incomeRange < int64(IncomeRangeMin) || incomeRange > int64(IncomeRangeMax) {
return IncomeRangeInvalid, fmt.Errorf("income range out of range: %d, expected %d-%d", incomeRange, IncomeRangeMin, IncomeRangeMax)
}
return types.IncomeRange(incomeRange), nil
return IncomeRange(incomeRange), nil
}

func parseListingStatus(listingStatus int64) (types.ListingStatus, error) {
if listingStatus < int64(types.ListingStatusMin) || listingStatus > int64(types.ListingStatusMax) {
return types.ListingStatusUnknown, fmt.Errorf("listing status out of range: %d, expected %d-%d", listingStatus, types.ListingStatusMin, types.ListingStatusMax)
func parseListingStatus(listingStatus int64) (ListingStatus, error) {
if listingStatus < int64(ListingStatusMin) || listingStatus > int64(ListingStatusMax) {
return ListingStatusUnknown, fmt.Errorf("listing status out of range: %d, expected %d-%d", listingStatus, ListingStatusMin, ListingStatusMax)
}
return types.ListingStatus(listingStatus), nil
return ListingStatus(listingStatus), nil
}

func parseFicoScore(ficoScore string) (types.FicoScore, error) {
stringToScore := map[string]types.FicoScore{
"<600": types.Below600,
"600-619": types.Between600And619,
"620-639": types.Between620And639,
"640-659": types.Between640And659,
"660-679": types.Between660And679,
"680-699": types.Between680And699,
"700-719": types.Between700And719,
"720-739": types.Between720And739,
"740-759": types.Between740And759,
"760-779": types.Between760And779,
"780-799": types.Between780And799,
"800-819": types.Between800And819,
"820-850": types.Between820And850,
func parseFicoScore(ficoScore string) (FicoScore, error) {
stringToScore := map[string]FicoScore{
"<600": Below600,
"600-619": Between600And619,
"620-639": Between620And639,
"640-659": Between640And659,
"660-679": Between660And679,
"680-699": Between680And699,
"700-719": Between700And719,
"720-739": Between720And739,
"740-759": Between740And759,
"760-779": Between760And779,
"780-799": Between780And799,
"800-819": Between800And819,
"820-850": Between820And850,
}
parsed, ok := stringToScore[ficoScore]
if !ok {
return types.FicoScoreInvalid, fmt.Errorf("unrecognized fico score: %s", ficoScore)
return FicoScoreInvalid, fmt.Errorf("unrecognized fico score: %s", ficoScore)
}
return parsed, nil
}
51 changes: 25 additions & 26 deletions prosper/listing_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@ import (
"time"

"github.com/mtlynch/gofn-prosper/prosper/thin"
"github.com/mtlynch/gofn-prosper/types"
)

func TestListingParser(t *testing.T) {
var tests = []struct {
input thin.SearchResult
want types.Listing
want Listing
expectSuccess bool
msg string
}{
Expand Down Expand Up @@ -73,7 +72,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -113,7 +112,7 @@ func TestListingParser(t *testing.T) {
TotalInquiries: 6,
LastUpdatedDate: "",
},
want: types.Listing{
want: Listing{
PriorProsperLoans: 0,
AmountDelinquent: 0,
AmountParticipation: 0,
Expand All @@ -124,7 +123,7 @@ func TestListingParser(t *testing.T) {
PublicRecordsLast12Months: 0,
TotalOpenRevolvingAccounts: 3,
VerificationStage: 2,
ListingStatus: types.ListingActive,
ListingStatus: ListingActive,
ListingTitle: "Large Purchases",
DelinquenciesLast7Years: 14,
EmploymentStatusDescription: "Other",
Expand All @@ -145,13 +144,13 @@ func TestListingParser(t *testing.T) {
ListingCategoryID: 14,
BorrowerCity: "PASADENA",
BorrowerState: "MD",
IncomeRange: types.Between25kAnd50k,
IncomeRange: Between25kAnd50k,
IncomeRangeDescription: "$25,000-49,999",
ProsperScore: 4,
RevolvingAvailablePercent: 72,
CurrentCreditLines: 2,
DtiWprosperLoan: 0.14,
FicoScore: types.Between660And679,
FicoScore: Between660And679,
FirstRecordedCreditLine: time.Date(1991, 3, 22, 8, 0, 0, 0, time.UTC),
RealEstateBalance: 0,
SatisfactoryAccounts: 23,
Expand All @@ -168,7 +167,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: types.RatingC,
Rating: RatingC,
BorrowerApr: 0.20777,
PriorProsperLoans31dpd: 0,
PriorProsperLoansLatePaymentsOneMonthPlus: 0,
Expand Down Expand Up @@ -223,7 +222,7 @@ func TestListingParser(t *testing.T) {
PercentFunded: 0.0,
PartialFundingIndicator: true,
FundingThreshold: 0.7,
ProsperRating: "A",
Rating: "A",
EstimatedReturn: 0.0431,
EstimatedLossRate: 0.0249,
LenderYield: 0.0674,
Expand Down Expand Up @@ -284,7 +283,7 @@ func TestListingParser(t *testing.T) {
IsHomeowner: false,
LastUpdatedDate: "2015-11-03 01:01:26 +0000",
},
want: types.Listing{
want: Listing{
MemberKey: "A9A73458009412ECD63F",
ListingNumber: 989367,
CreditPullDate: time.Date(2015, 11, 2, 3, 36, 21, 0, time.UTC),
Expand All @@ -299,7 +298,7 @@ func TestListingParser(t *testing.T) {
PercentFunded: 0.0,
PartialFundingIndicator: true,
FundingThreshold: 0.7,
ProsperRating: types.RatingA,
Rating: RatingA,
EstimatedReturn: 0.0431,
EstimatedLossRate: 0.0249,
LenderYield: 0.0674,
Expand All @@ -309,10 +308,10 @@ func TestListingParser(t *testing.T) {
ListingTerm: 36,
ListingMonthlyPayment: 624.33,
ScoreX: "778+",
FicoScore: types.Between780And799,
FicoScore: Between780And799,
ListingCategoryID: 1,
ListingTitle: "Debt consolidation",
IncomeRange: types.Over100k,
IncomeRange: Over100k,
IncomeRangeDescription: "$100,000+",
StatedMonthlyIncome: 8333.33,
IncomeVerifiable: true,
Expand Down Expand Up @@ -417,7 +416,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -517,7 +516,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -617,7 +616,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -717,7 +716,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "invalid rating", // invalid
Rating: "invalid rating", // invalid
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -817,7 +816,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -917,7 +916,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -1017,7 +1016,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -1117,7 +1116,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -1217,7 +1216,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -1317,7 +1316,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -1417,7 +1416,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -1517,7 +1516,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down Expand Up @@ -1617,7 +1616,7 @@ func TestListingParser(t *testing.T) {
MonthlyDebt: 144,
MonthsEmployed: 72,
PartialFundingIndicator: true,
ProsperRating: "C",
Rating: "C",
BorrowerApr: 0.20777,
GroupName: "",
ListingPurpose: "",
Expand Down

0 comments on commit c0f6a79

Please sign in to comment.