-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create /metrics with MAC #177
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import * as React from "react"; | ||
import { connect, MapStateToProps } from "react-redux"; | ||
import { Map } from "immutable"; | ||
import { MemberId } from "@raha/api-shared/dist/models/identifiers"; | ||
import { Operation } from "@raha/api-shared/dist/models/Operation"; | ||
import { AppState } from "../store"; | ||
import { Loading } from "../components/Loading"; | ||
import { Member } from "../reducers/membersNew"; | ||
|
||
interface OwnProps {} | ||
|
||
interface StateProps { | ||
operations: Operation[]; | ||
members: Map<MemberId, Member>; | ||
} | ||
|
||
type Props = OwnProps & StateProps; | ||
|
||
/** | ||
* TODO this calculation should really be a cached (reselect?) connector. | ||
* TODO date and duration parameters. | ||
* | ||
* Returns MAC, our "monthly active creators" metric which | ||
* means the number of verified users who have created a | ||
* public transaction within the last 30 days. | ||
*/ | ||
function getMac(operations: Operation[], members: Map<MemberId, Member>) { | ||
const lastMonth = new Date(); | ||
lastMonth.setDate(lastMonth.getDate() - 30); | ||
const memberIdSet = new Set(); | ||
for (let i = operations.length - 1; i >= 0; i--) { | ||
const op = operations[i]; | ||
if (new Date(op.created_at) < lastMonth) { | ||
break; | ||
} | ||
const member = members.get(op.creator_uid); | ||
if (member && member.get("isVerified")) { | ||
memberIdSet.add(op.creator_uid); | ||
} | ||
} | ||
return memberIdSet.size; | ||
} | ||
|
||
// TODO improve styling, don't rely on h1/h2/h3, add graphs | ||
const MetricsView: React.StatelessComponent<Props> = props => { | ||
const { members, operations } = props; | ||
if (!operations || operations.length === 0) { | ||
return <Loading />; | ||
} | ||
return ( | ||
<section style={{ margin: "20px" }}> | ||
<h2>MAC (Monthly Active Creators)</h2> | ||
<h3> | ||
How many verified members have created at least one transaction in the | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit on word operation over transaction |
||
last 30 days? | ||
</h3> | ||
<h1>{getMac(operations, members)}</h1> | ||
</section> | ||
); | ||
}; | ||
|
||
const mapStateToProps: MapStateToProps< | ||
StateProps, | ||
OwnProps, | ||
AppState | ||
> = state => { | ||
return { | ||
operations: state.operations, | ||
members: state.membersNew.byMemberId | ||
}; | ||
}; | ||
|
||
export const Metrics = connect(mapStateToProps)(MetricsView); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I think we're standardized on the word
operation
.