Skip to content

Commit

Permalink
Merge pull request #180 from dracor-org/173-naming
Browse files Browse the repository at this point in the history
Align field and column names with DraCor wording
  • Loading branch information
cmil authored Sep 22, 2024
2 parents b4501de + 284b89e commit ebb82d7
Show file tree
Hide file tree
Showing 14 changed files with 5,198 additions and 5,155 deletions.
9,546 changes: 4,773 additions & 4,773 deletions data.yaml

Large diffs are not rendered by default.

576 changes: 288 additions & 288 deletions originals.yaml

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/about.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ from different environments to conduct statistics. An example in R:
```R
library(jsonlite)
einakter <- fromJSON("https://einakter.dracor.org/data.json")
hist(einakter$normalizedYear, breaks = 20, xlab="Jahrfünft", ylab="Anzahl Stücke im Korpus")
plot(einakter$normalizedYear, einakter$numberOfScenes, xlab="Jahr", ylab="Anzahl Szenen pro Stück")
plot(einakter$normalizedYear, einakter$numberOfCharacters, xlab="Jahr", ylab="Anzahl Figuren pro Stück")
hist(einakter$yearNormalized, breaks = 20, xlab="Jahrfünft", ylab="Anzahl Stücke im Korpus")
plot(einakter$yearNormalized, einakter$numOfScenes, xlab="Jahr", ylab="Anzahl Szenen pro Stück")
plot(einakter$yearNormalized, einakter$numOfCharacters, xlab="Jahr", ylab="Anzahl Figuren pro Stück")
```

The data model is described <a href="https://github.com/dracor-org/einakter/wiki">here</a>.
Expand Down
16 changes: 10 additions & 6 deletions src/components/Details.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ export default function Details() {
authors = [],
cast,
comments,
created,
yearWritten,
yearPrinted,
dictionaries,
editions,
formalia,
ids,
keywords,
numberOfScenes,
numOfScenes,
premiered,
printed,
reviews,
settings,
basedOn,
Expand Down Expand Up @@ -129,15 +129,19 @@ export default function Details() {
<Trans>Dates</Trans>
</th>
<td>
<Years written={created} premiere={premiered} print={printed} />
<Years
written={yearWritten}
premiere={premiered}
print={yearPrinted}
/>
</td>
</tr>
{numberOfScenes && (
{numOfScenes && (
<tr>
<th>
<Trans>Number of Scenes</Trans>
</th>
<td>{numberOfScenes}</td>
<td>{numOfScenes}</td>
</tr>
)}
{ids && (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Map.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const SettingsMap = () => {
authors: p.authors || [],
title: p.title,
slug: p.slug,
year: p.normalizedYear,
year: p.yearNormalized,
setting: s.description,
});
}
Expand Down
6 changes: 3 additions & 3 deletions src/components/Original.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import {localLanguageName} from '../languages';

function getYear(ref: OriginalPlay) {
const years = [];
if (ref.created) years.push(ref.created);
if (ref.printed) years.push(ref.printed);
if (ref.yearWritten) years.push(ref.yearWritten);
if (ref.yearPrinted) years.push(ref.yearPrinted);
if (ref.premiered) years.push(parseInt(ref.premiered as string));
return years.sort()[0] || undefined;
}
Expand Down Expand Up @@ -95,7 +95,7 @@ const Original = ({data}: Props) => {
{play.title}
{play.subtitle && !play.title.match(/[.!?]\s*$/) && '.'}
{play.subtitle && ` ${play.subtitle}`}
{play.normalizedYear && ` (${play.normalizedYear})`}
{play.yearNormalized && ` (${play.yearNormalized})`}
</Link>
</li>
))}
Expand Down
12 changes: 8 additions & 4 deletions src/components/OriginalDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ const OriginalDetails = () => {
title,
subtitle,
ids,
created,
yearWritten,
premiered,
printed,
yearPrinted,
fulltextUrl,
language,
} = original;
Expand Down Expand Up @@ -87,7 +87,7 @@ const OriginalDetails = () => {
{play.title}
{play.subtitle && !play.title.match(/[.!?]\s*$/) && '.'}
{play.subtitle && ` ${play.subtitle}`}
{play.normalizedYear && ` (${play.normalizedYear})`}
{play.yearNormalized && ` (${play.yearNormalized})`}
</Link>
</li>
))}
Expand All @@ -99,7 +99,11 @@ const OriginalDetails = () => {
<Trans>Dates</Trans>
</th>
<td>
<Years written={created} premiere={premiered} print={printed} />
<Years
written={yearWritten}
premiere={premiered}
print={yearPrinted}
/>
</td>
</tr>
{ids && (
Expand Down
8 changes: 4 additions & 4 deletions src/components/Originals.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ function Originals() {
cell: (info) => <TitleCell play={info.row.original} />,
},
{
id: 'normalizedYear',
id: 'yearNormalized',
header: t`Year (normalized)`,
accessorFn: (row) => row.normalizedYear?.toString() || '',
accessorFn: (row) => row.yearNormalized?.toString() || '',
cell: (info) => (
<span>{formatEra(info.row.original.normalizedYear)}</span>
<span>{formatEra(info.row.original.yearNormalized)}</span>
),
},
{
Expand All @@ -88,7 +88,7 @@ function Originals() {
<Table
columns={columns}
data={data}
defaultSort={[{id: 'normalizedYear', desc: false}]}
defaultSort={[{id: 'yearNormalized', desc: false}]}
/>
</div>
</div>
Expand Down
20 changes: 10 additions & 10 deletions src/components/Plays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,32 +56,32 @@ export default function Plays() {
cell: (info) => <TitleCell play={info.row.original} urlPath="/" />,
},
{
id: 'normalizedYear',
id: 'yearNormalized',
header: t`Year (normalized)`,
accessorFn: (row) => row.normalizedYear?.toString() || '',
accessorFn: (row) => row.yearNormalized?.toString() || '',
cell: ({
row: {
original: {normalizedYear},
original: {yearNormalized},
},
}) => {
return (
<span>
{normalizedYear == null
{yearNormalized == null
? t`not available`
: formatEra(normalizedYear)}
: formatEra(yearNormalized)}
</span>
);
},
},
{
id: 'numberOfScenes',
id: 'numOfScenes',
header: t`Scenes`,
accessorFn: (row) => row.numberOfScenes?.toString() || '',
accessorFn: (row) => row.numOfScenes?.toString() || '',
},
{
id: 'numberOfCharacters',
id: 'numOfCharacters',
header: t`Characters`,
accessorFn: (row) => row.numberOfCharacters?.toString() || '',
accessorFn: (row) => row.numOfCharacters?.toString() || '',
},
{
id: 'keywords',
Expand Down Expand Up @@ -124,7 +124,7 @@ export default function Plays() {
<Table
columns={columns}
data={data}
defaultSort={[{id: 'normalizedYear', desc: false}]}
defaultSort={[{id: 'yearNormalized', desc: false}]}
/>
</div>
</>
Expand Down
20 changes: 11 additions & 9 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,12 @@ export interface Play {
basedOnLanguage?: string;
cast?: CastMember[];
comments?: string[];
created?: number;
yearWritten?: number;
yearPrinted?: number;
yearPremiered?: number;
datePremiered?: string;
yearNormalized?: number;
premiered?: string | number;
editions?: Edition[];
dictionaries?: Dict[];
formalia?: string[];
Expand All @@ -69,11 +74,8 @@ export interface Play {
weber?: string;
};
keywords?: string[];
normalizedYear?: number;
numberOfCharacters?: number;
numberOfScenes?: number;
premiered?: string | number;
printed?: number;
numOfCharacters?: number;
numOfScenes?: number;
reviews?: string[];
settings?: Setting[];
subtitle?: string;
Expand All @@ -87,10 +89,10 @@ export interface OriginalPlay {
title: string;
subtitle?: string;
language?: string;
created?: number;
printed?: number;
yearWritten?: number;
yearPrinted?: number;
premiered?: string | number;
normalizedYear?: number;
yearNormalized?: number;
fulltextUrl?: string;
ids?: {
dracor?: string;
Expand Down
23 changes: 14 additions & 9 deletions src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,26 +23,26 @@ describe('normalizeYear', () => {
expect(normalizeYear(play)).toBe(1789);
});

it('uses earlier year of "premiered" and "printed"', () => {
const play = {...playTmpl, premiered: 1789, printed: 1805};
it('uses earlier year of "premiered" and "yearPrinted"', () => {
const play = {...playTmpl, premiered: 1789, yearPrinted: 1805};
expect(normalizeYear(play)).toBe(1789);

const play2 = {...playTmpl, premiered: 1805, printed: 1777};
const play2 = {...playTmpl, premiered: 1805, yearPrinted: 1777};
expect(normalizeYear(play2)).toBe(1777);
});

it('uses "created" when it is the only defined year', () => {
const play = {...playTmpl, created: 1777};
it('uses "yearWritten" when it is the only defined year', () => {
const play = {...playTmpl, yearWritten: 1777};
expect(normalizeYear(play)).toBe(1777);
});

it('uses "created" when it is more than 10 years before publication', () => {
const play = {...playTmpl, premiered: 1810, created: 1777};
it('uses "yearWritten" when it is more than 10 years before publication', () => {
const play = {...playTmpl, premiered: 1810, yearWritten: 1777};
expect(normalizeYear(play)).toBe(1777);
});

it('prefers publication year when less than 10 years after creation', () => {
const play = {...playTmpl, premiered: 1810, created: 1805};
const play = {...playTmpl, premiered: 1810, yearWritten: 1805};
expect(normalizeYear(play)).toBe(1810);
});
});
Expand Down Expand Up @@ -75,7 +75,12 @@ describe('countCharactersByGender', () => {

describe('getEarliestYear', () => {
it('finds earliest year', () => {
const play = {...playTmpl, premiered: 1789, created: 1770, printed: 1790};
const play = {
...playTmpl,
premiered: 1789,
yearWritten: 1770,
yearPrinted: 1790,
};
expect(getEarliestYear(play)).toBe(1770);
});

Expand Down
26 changes: 15 additions & 11 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
import {Play, OriginalPlay} from './types';

export function normalizeYear(play: Play | OriginalPlay) {
const {premiered: p, printed, created} = play;
const {premiered: p, yearPrinted, yearWritten} = play;
const premiered: number = parseInt(p as string);
const published =
premiered && printed ? Math.min(premiered, printed) : premiered || printed;
premiered && yearPrinted
? Math.min(premiered, yearPrinted)
: premiered || yearPrinted;

let year;
if (created && published) {
year = published - created > 10 ? created : published;
if (yearWritten && published) {
year = published - yearWritten > 10 ? yearWritten : published;
} else {
year = created || published;
year = yearWritten || published;
}

return year;
}

export function getEarliestYear(play: Play) {
const {premiered, printed, created} = play;
const years = [parseInt(premiered as string), printed, created].filter((y) =>
Boolean(y)
);
const {premiered, yearPrinted, yearWritten} = play;
const years = [
parseInt(premiered as string),
yearPrinted,
yearWritten,
].filter((y) => Boolean(y));
return years.length > 0 ? Math.min(...(years as number[])) : undefined;
}

Expand Down Expand Up @@ -56,8 +60,8 @@ export function countCharactersByGender(play: Play) {
}

export function sortByYear(a: Play, b: Play) {
const yearA = a.normalizedYear || -10000;
const yearB = b.normalizedYear || -10000;
const yearA = a.yearNormalized || -10000;
const yearB = b.yearNormalized || -10000;
if (yearA > yearB) return 1;
if (yearA < yearB) return -1;
return 0;
Expand Down
Loading

0 comments on commit ebb82d7

Please sign in to comment.