Skip to content

Classes and Types for EventStream Puzzler #128

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

Open
wants to merge 34 commits into
base: kameron-eventstream-puzzler
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6cfd596
Create types file and add eventinterface
KameronKeller Apr 3, 2024
40c887e
Create files for classes
KameronKeller Apr 3, 2024
51e7f33
Create events file and define class
KameronKeller Apr 3, 2024
ca9c292
Define main function and add console log to ensure it is working
KameronKeller Apr 3, 2024
eec3d8d
Import interface
KameronKeller Apr 3, 2024
ca79bbd
Add type for EventStreamInterface
KameronKeller Apr 3, 2024
9a1c22e
Rename to avoid already used classname Event
KameronKeller Apr 3, 2024
3d81a16
Implement event stream class
KameronKeller Apr 3, 2024
08f1c6d
Add score member variable to appevent
KameronKeller Apr 3, 2024
d06b73a
Use the defined interface for the type of events
KameronKeller Apr 3, 2024
acc6c01
Implement the Region class
KameronKeller Apr 3, 2024
236180b
Implement the static scores class
KameronKeller Apr 3, 2024
bff2c8d
Add a type for the Scores dictionary and rename the type
KameronKeller Apr 3, 2024
68073e4
Implement initial HighestRegionLocator class
KameronKeller Apr 3, 2024
f193f0d
Add high level tests for the defined classes
KameronKeller Apr 3, 2024
ba9fc52
Change the events type from the interface to the class type
KameronKeller Apr 3, 2024
ee73559
Add sample data as an asset to the project for future testing
KameronKeller Apr 3, 2024
5ce0923
Remove semicolons
KameronKeller Apr 4, 2024
5b0af2f
Remove semicolons
KameronKeller Apr 4, 2024
7ed70ec
Use const when able
KameronKeller Apr 4, 2024
1706597
Replace double quotes with single quotes
KameronKeller Apr 4, 2024
d6770a7
Remove instantiation of region object test
KameronKeller Apr 4, 2024
56cbf8d
Switch function definition to es6 format
KameronKeller Apr 4, 2024
405b530
Move score retrieval function to utilities file and remove scores class
KameronKeller Apr 4, 2024
4b69bdf
Remove scores.ts file
KameronKeller Apr 4, 2024
1abea6d
Replace appevent and eventstream classes with types and remove class …
KameronKeller Apr 4, 2024
ecdc8bf
Add type for sample data
KameronKeller Apr 4, 2024
5b2e077
Change filename to camelcase
KameronKeller Apr 5, 2024
ef3b515
Renamed data to sampleData and changed to single quotes
KameronKeller Apr 5, 2024
72c00e9
Remove score variable that is not needed/used
KameronKeller Apr 5, 2024
058127a
Remove dead code and unneeded tests
KameronKeller Apr 5, 2024
f298910
Change scores dictionary to type instead of interface
KameronKeller Apr 5, 2024
cfb2da6
Remove dead code
KameronKeller Apr 5, 2024
f24ad40
Remove dead code
KameronKeller Apr 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions src/assets/sampleData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { EventStream } from '../types';

export const sampleData: EventStream = [
{
timestamp: 123123123,
eventType: 'newMessage',
},
{
timestamp: 123123124,
eventType: 'newMessage',
},
{
timestamp: 123123125,
eventType: 'newMessage',
},
{
timestamp: 123123125,
eventType: 'view',
},
{
timestamp: 123123125,
eventType: 'view',
},
{
timestamp: 123123125,
eventType: 'screenshot',
},
{
timestamp: 123123125,
eventType: 'screenshot',
},
{
timestamp: 123123125,
eventType: 'newMessage',
},
{
timestamp: 123123125,
eventType: 'newMessage',
}
]
40 changes: 36 additions & 4 deletions src/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,39 @@
//write tests here
import { AppEvent } from './types'
import { Region } from './models/region'
import { retrieveScoreByEventType } from './utils/utils'

describe('Tests will go here!', () => {
it('should pass', () => {
expect(true).toBeTruthy()
describe('Region', () => {

const appEvent: AppEvent =
{
timestamp: 123123123,
eventType: 'newMessage',
}

it('adds an AppEvent to a region', () => {
const region = new Region()
region.addAppEvent(appEvent)
expect(region.regionEvents.length).toEqual(1)
})

it('totals up the score of a region', () => {
const region = new Region()
region.addAppEvent(appEvent)
expect(region.getScore()).toEqual(1)
})
})

describe('RetrieveScoreByEventType', () => {

it('provides the correct score for event type: newMessage', () => {
expect(retrieveScoreByEventType('newMessage')).toEqual(1)
})

it('provides the correct score for event type: view', () => {
expect(retrieveScoreByEventType('view')).toEqual(2)
})

it('provides the correct score for event type: screenshot', () => {
expect(retrieveScoreByEventType('screenshot')).toEqual(3)
})
})
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
//Define class here
const main = () => {
console.log('main is running')
}

main()
15 changes: 15 additions & 0 deletions src/models/highestRegionLocator.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Region } from './region'
import { EventStream } from '../types'

export class HighestRegionLocator {
eventStream: EventStream

constructor(eventStream: EventStream) {
this.eventStream = eventStream
}

locateHighestRegion(): Region {
throw console.error('This is not implemented yet')
return new Region()
}
}
18 changes: 18 additions & 0 deletions src/models/region.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { retrieveScoreByEventType } from '../utils/utils'
import { AppEvent } from '../types'

export class Region {
regionEvents: AppEvent[] = []

addAppEvent(appEvent: AppEvent): void {
this.regionEvents.push(appEvent)
}

getScore(): number {
let totalScore = 0
for (let appEvent of this.regionEvents) {
totalScore += retrieveScoreByEventType(appEvent.eventType)
}
return totalScore
}
}
10 changes: 10 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export type AppEvent = {
timestamp: number,
eventType: string,
}

export type EventStream = AppEvent[]

export type ScoresDictionary = {
[index: string]: number,
}
11 changes: 11 additions & 0 deletions src/utils/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { ScoresDictionary } from '../types'

const SCORES: ScoresDictionary = {
'newMessage': 1,
'view': 2,
'screenshot': 3
}

export const retrieveScoreByEventType = (eventType: string): number => {
return SCORES[eventType]
}