-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from burningmantech/reflex
Add Reflex app
- Loading branch information
Showing
35 changed files
with
1,413 additions
and
406 deletions.
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 |
---|---|---|
|
@@ -10,5 +10,7 @@ __pycache__/ | |
/dist/ | ||
/htmlcov/ | ||
/htmldocs/ | ||
/reflex_app/.web/ | ||
/rtx.sqlite | ||
/src/*.egg-info/ | ||
/wheels/ |
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
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
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,13 @@ | ||
""" | ||
Transmissions Reflex Application | ||
""" | ||
|
||
from .app import searchIndexFactory, storeFactory | ||
from .pages import transmissionsListPage | ||
|
||
|
||
__all__ = [ | ||
"searchIndexFactory", | ||
"storeFactory", | ||
"transmissionsListPage", | ||
] |
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,71 @@ | ||
""" | ||
Application | ||
""" | ||
|
||
from os import environ | ||
from pathlib import Path | ||
|
||
from reflex import App | ||
from twisted.logger import Logger | ||
|
||
from transmissions.ext.click import readConfig | ||
from transmissions.ext.logger import startLogging | ||
from transmissions.run._search import searchIndexFactoryFromConfig # FIXME: private | ||
from transmissions.run._store import storeFactoryFromConfig # FIXME: private | ||
from transmissions.search import TransmissionsIndex | ||
from transmissions.store import TXDataStore | ||
|
||
|
||
log = Logger() | ||
|
||
|
||
class StoreFactory: | ||
""" | ||
Factory for data store. | ||
""" | ||
|
||
_store: TXDataStore | None = None | ||
|
||
async def store(self) -> TXDataStore: | ||
""" | ||
Get and cache the data store. | ||
""" | ||
if self._store is None: | ||
log.info("Initializing data store...") | ||
storeFactory = storeFactoryFromConfig(configuration, create=False) | ||
self._store = await storeFactory() | ||
|
||
return self._store | ||
|
||
|
||
class SearchIndexFactory: | ||
""" | ||
Factory for search index. | ||
""" | ||
|
||
_index: TransmissionsIndex | None = None | ||
|
||
async def index(self, store: TXDataStore) -> TransmissionsIndex: | ||
""" | ||
Get and cache the search index. | ||
""" | ||
if self._index is None: | ||
log.info("Initializing search index...") | ||
searchIndexFactory = searchIndexFactoryFromConfig(configuration) | ||
self._index = await searchIndexFactory(store) | ||
|
||
return self._index | ||
|
||
|
||
startLogging() | ||
|
||
defaultConfigPath = Path("~/.rtx.toml") # FIXME: Not DRY; see _command.py | ||
fileName = environ.get("CONFIG", defaultConfigPath) | ||
|
||
log.info("Reading configuration file: {file}", file=fileName) | ||
configuration = readConfig(Path(fileName)) | ||
|
||
storeFactory = StoreFactory() | ||
searchIndexFactory = SearchIndexFactory() | ||
|
||
app = App() |
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,10 @@ | ||
""" | ||
Reflex-compatible data models | ||
""" | ||
|
||
from ._transmission import RXTransmission | ||
|
||
|
||
__all__ = [ | ||
"RXTransmission", | ||
] |
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,47 @@ | ||
from typing import ClassVar, Self, overload | ||
|
||
from reflex import Base | ||
|
||
from transmissions.model import Transmission, TZInfo | ||
|
||
|
||
class RXTransmission(Base): | ||
""" | ||
Reflex model for Transmission | ||
""" | ||
|
||
dateTimeFormat: ClassVar[str] = "%y-%m-%d %H:%M:%S%z" | ||
|
||
@overload | ||
@classmethod | ||
def fromTransmission(cls, transmission: Transmission) -> Self: ... | ||
|
||
@overload | ||
@classmethod | ||
def fromTransmission(cls, transmission: None) -> None: ... | ||
|
||
@classmethod | ||
def fromTransmission(cls, transmission: Transmission | None) -> Self | None: | ||
if transmission is None: | ||
return None | ||
return cls( | ||
startTime=transmission.startTime.astimezone(TZInfo.PDT.value).strftime( | ||
cls.dateTimeFormat | ||
), | ||
eventID=transmission.eventID, | ||
station=transmission.station, | ||
system=transmission.system, | ||
channel=transmission.channel, | ||
duration=( | ||
transmission.duration.total_seconds() if transmission.duration else None | ||
), | ||
transcription=transmission.transcription, | ||
) | ||
|
||
startTime: str | ||
eventID: str | ||
station: str | ||
system: str | ||
channel: str | ||
duration: float | None | ||
transcription: str | None |
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,10 @@ | ||
""" | ||
Reflex page components | ||
""" | ||
|
||
from ._list import transmissionsListPage | ||
|
||
|
||
__all__ = [ | ||
"transmissionsListPage", | ||
] |
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,10 @@ | ||
""" | ||
Transmissions List Page | ||
""" | ||
|
||
from ._page import transmissionsListPage | ||
|
||
|
||
__all__ = [ | ||
"transmissionsListPage", | ||
] |
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,55 @@ | ||
""" | ||
Transmissions filters | ||
""" | ||
|
||
from reflex import Component, form, hstack, input, select, vstack | ||
|
||
from ._state import State | ||
|
||
|
||
def transmissionsFilters() -> Component: | ||
""" | ||
Transmissions filters | ||
""" | ||
return ( | ||
form( | ||
vstack( | ||
hstack( | ||
form.field( | ||
form.label("Event"), | ||
select( | ||
State.events, | ||
value=State.selectedEvent, | ||
on_change=State.eventSelected, | ||
label="Event", | ||
), | ||
), | ||
form.field( | ||
form.label("Start"), | ||
input( | ||
type="datetime-local", | ||
name="start_time", | ||
placeholder="Start Time", | ||
value=State.startTime, | ||
on_change=State.startTimeEdited, | ||
), | ||
), | ||
form.field( | ||
form.label("End"), | ||
input( | ||
type="datetime-local", | ||
name="end_time", | ||
value=State.endTime, | ||
on_change=State.endTimeEdited, | ||
), | ||
), | ||
), | ||
input( | ||
type="search", | ||
name="search_text", | ||
placeholder="Search…", | ||
on_blur=State.searchEdited, | ||
), | ||
), | ||
), | ||
) |
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,61 @@ | ||
""" | ||
Transmission Info | ||
""" | ||
|
||
from reflex import ( | ||
Component, | ||
audio, | ||
blockquote, | ||
card, | ||
code, | ||
cond, | ||
divider, | ||
heading, | ||
text, | ||
vstack, | ||
) | ||
|
||
from ._state import State | ||
|
||
|
||
def selectedTransmissionInfo() -> Component: | ||
""" | ||
Information about the selected transmission. | ||
""" | ||
transmission = State.selectedTransmission | ||
|
||
return cond( | ||
transmission, | ||
card( | ||
vstack( | ||
heading("Selected Transmission", as_="h2"), | ||
divider(), | ||
text( | ||
"Station ", | ||
code(transmission.station), | ||
" on channel ", | ||
code(transmission.channel), | ||
" at ", | ||
text.strong(transmission.startTime), | ||
), | ||
divider(), | ||
text("Transcript:"), | ||
blockquote(transmission.transcription), | ||
divider(), | ||
audio( | ||
url=State.selectedTransmissionAudioURL, | ||
width="100%", | ||
height="32px", | ||
), | ||
width="100%", | ||
), | ||
width="100%", | ||
), | ||
card( | ||
vstack( | ||
text("No transmission selected"), | ||
width="100%", | ||
), | ||
width="100%", | ||
), | ||
) |
Oops, something went wrong.