Skip to content

Commit

Permalink
git init
Browse files Browse the repository at this point in the history
  • Loading branch information
witcat committed Sep 5, 2024
0 parents commit 8adfbfc
Show file tree
Hide file tree
Showing 54 changed files with 10,813 additions and 0 deletions.
13 changes: 13 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Daily Cloudflare Pages Deploy

on:
schedule:
- cron: '0 3 * * *'

jobs:
deploy:
runs-on: ubuntu-latest

steps:
- name: Trigger Cloudflare Pages Deploy Hook
run: curl -X POST ${{ secrets.CLOUDFLARE_DEPLOY_HOOK_URL }}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "ipricepro",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "witcat",
"license": "ISC",
"devDependencies": {
"@types/is-url": "^1.2.32",
"@types/node": "^20.14.9",
"@vitest/coverage-v8": "^2.0.4",
"is-url": "^1.2.4",
"tsx": "^4.16.2",
"typescript": "^5.5.3",
"vitest": "^2.0.4"
},
"dependencies": {
"date-fns": "^3.6.0",
"es-toolkit": "^1.16.0"
},
"scripts": {
"lint-all": "pnpm --parallel lint"
}
}
207 changes: 207 additions & 0 deletions packages/guide/AppleProducts.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
import { Category } from "shared";
import type { ProductNames } from "shared";
import type { Product } from "./types";

export const products: {
[K in Category]: {
[P in ProductNames<K>]: Product;
};
} = {
[Category.IOS]: {
ipad_pro: {
releases: [
"2024-05-07",
"2022-10-18",
"2021-04-20",
"2020-03-18",
"2018-10-30",
"2017-06-05",
"2016-03-21",
],
},
ipad_air: {
releases: [
"2024-05-07",
"2022-03-08",
"2020-09-15",
"2019-03-18",
"2016-09-07",
"2014-10-16",
"2013-10-22",
],
},
iphone_15: {
releases: [
"2023-09-22",
"2022-09-16",
"2021-09-24",
"2020-10-23",
"2019-09-20",
"2018-10-26",
"2017-09-22",
],
},
iphone_15_pro: {
releases: [
"2023-09-22",
"2022-09-16",
"2021-09-24",
"2020-10-23",
"2019-09-20",
"2018-09-21",
"2017-11-03",
],
},
ipad: {
releases: [
"2022-10-18",
"2021-09-14",
"2020-09-15",
"2019-09-10",
"2018-03-27",
"2017-03-21",
"2012-10-23",
],
},
iphone_se: {
releases: ["2022-03-18", "2020-04-24", "2017-03-21", "2016-03-31"],
},
ipad_mini: {
releases: [
"2021-09-14",
"2019-03-18",
"2015-09-09",
"2014-10-16",
"2013-10-22",
"2012-10-23",
],
},
},
[Category.MAC]: {
macbook_air_13: {
releases: [
"2024-03-04",
"2022-07-08",
"2020-11-10",
"2020-03-18",
"2019-07-09",
"2018-10-30",
"2017-06-05",
],
},
macbook_air_15: {
releases: ["2024-03-04", "2023-06-05"],
},
macbook_pro_14: {
releases: [
"2023-10-30",
"2023-01-17",
"2021-10-18",
"2019-11-13",
"2019-05-21",
"2018-07-12",
"2017-06-05",
],
},
macbook_pro_16: {
releases: [
"2023-10-30",
"2023-01-17",
"2021-10-18",
"2019-11-13",
"2019-05-21",
"2018-07-12",
"2017-06-05",
],
},
imac: {
releases: [
"2023-10-30",
"2021-04-30",
"2020-08-04",
"2019-03-19",
"2017-06-05",
"2015-10-13",
"2015-05-19",
],
},
mac_pro: {
releases: [
"2023-06-05",
"2019-11-10",
"2013-11-18",
"2012-06-11",
"2010-07-27",
"2009-03-03",
"2008-01-08",
],
},
mac_studio: {
releases: ["2023-06-05", "2022-03-08"],
},
mac_mini: {
releases: [
"2023-01-17",
"2020-11-10",
"2020-03-18",
"2018-10-30",
"2014-10-16",
"2012-10-23",
"2011-07-20",
],
},
},
[Category.MUSIC]: {
airpods: {
releases: ["2021-10-26", "2019-03-20", "2016-11-03"],
},
airpods_pro: {
releases: ["2023-09-12", "2022-09-07", "2019-10-28"],
},
airpods_max: {
releases: ["2020-11-15"],
estimatedUpdate: 1460,
},
homepod: {
releases: ["2023-02-03", "2018-02-09"],
},
homepod_mini: {
releases: ["2020-11-16"],
estimatedUpdate: 1825,
},
},
[Category.OTHER]: {
vision_pro: {
releases: ["2024-02-02"],
estimatedUpdate: 1460,
},
apple_watch: {
releases: [
"2023-09-22",
"2022-09-16",
"2021-10-15",
"2020-09-18",
"2019-09-20",
"2018-09-21",
"2017-09-22",
],
},
apple_watch_ultra: {
releases: ["2023-09-22", "2022-09-23"],
},
apple_watch_se: {
releases: ["2022-09-16", "2020-09-18"],
},
apple_tv: {
releases: [
"2022-11-04",
"2021-05-21",
"2017-09-22",
"2015-10-30",
"2013-03-10",
"2012-03-07",
"2020-09-01",
],
},
},
};
70 changes: 70 additions & 0 deletions packages/guide/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { addDays, subDays } from "date-fns";
import { getDateStringAndDifference, getSuggestion, stringToUTCDate } from ".";
import { expect, it } from "vitest";
import { Conclusion, Product } from "./types";

/**
* average 495
* 33% 165
* 66% 330
* 83% 412
*/
const iPadPro: Product = {
releases: [
"2024-05-07",
"2022-10-18",
"2021-04-20",
"2020-03-18",
"2018-10-30",
"2017-06-05",
"2016-03-21",
],
};

const HomePodmini: Product = {
releases: ["2020-11-16"],
estimatedUpdate: 1825,
};

const May7th = new Date(Date.UTC(2024, 4, 7));
const _160DaysLater = addDays(May7th, 160);
const _170DaysLater = addDays(May7th, 170);
const _410DaysLater = addDays(May7th, 410);
const _420DaysLater = addDays(May7th, 420);

const Nov16th = new Date(Date.UTC(2020, 10, 16));
const _1500DaysLater = addDays(Nov16th, 1500);

it("should get correct conclusion.", () => {
expect(getSuggestion(iPadPro, _160DaysLater, "en").conclusion).toBe(
Conclusion.BUY_NOW
);
expect(getSuggestion(iPadPro, _170DaysLater, "en").conclusion).toBe(
Conclusion.NEUTRAL
);
expect(getSuggestion(iPadPro, _410DaysLater, "en").conclusion).toBe(
Conclusion.CAUTION
);
expect(getSuggestion(iPadPro, _420DaysLater, "en").conclusion).toBe(
Conclusion.DONT_BUY
);
});
it("should convert yyyy-mm-dd to UTC Date.", () => {
expect(stringToUTCDate("2024-05-07")).toEqual(new Date(Date.UTC(2024, 4, 7)));
});
it("should return correct distance in days.", () => {
expect(
getDateStringAndDifference(subDays(new Date(), 1), new Date(), "en")[1]
).toBe(1);
});

it("should get correct release span average.", () => {
expect(getSuggestion(iPadPro, _160DaysLater, "en").average).toBe(495);
expect(getSuggestion(iPadPro, _410DaysLater, "en").average).toBe(495);
});

it("should get correct conclusion when there is no recent releases.", () => {
expect(getSuggestion(HomePodmini, _1500DaysLater, "en").conclusion).toBe(
Conclusion.CAUTION
);
});
Loading

0 comments on commit 8adfbfc

Please sign in to comment.