Skip to content

Commit

Permalink
Merge 33229ec into e19eb55
Browse files Browse the repository at this point in the history
  • Loading branch information
vokimon committed Jul 19, 2022
2 parents e19eb55 + 33229ec commit 69bbcfc
Show file tree
Hide file tree
Showing 16 changed files with 214 additions and 151 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@

- Update notes:
- npm install required (emotion and babel dependencies)
- config.yaml `callinfoPath` should point to the parent of current `my_calls_log`.
If not specified it will be `callinfo` by default (relative to the working path).
- config.yaml: `my_calls_log` should be removed

## 4.6.0 2022-07-12

Expand Down
3 changes: 2 additions & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
- [ ] Ask before deleting, killing, uploading...
- Scheduler:
- [ ] Join load computation into the scheduler script
- [ ] Like we did with callinfo, review files loaded and dumped to rationalize it
- Person editor:
- [ ] Disable ok until all fields are valid
- [ ] Check extension not taken already
Expand All @@ -29,7 +30,7 @@
- [ ] List/admin mode
- [ ] Nicer date picker for one-shot busy
- Callinfo
- [ ] config `callinfo_data` instead of `my_calls_log` parent folder
- [x] config `callinfoPath` instead of `my_calls_log` parent folder
- [ ] Edit previous annotations
- [ ] /api/info/ringring -> api/call/ringring (ext) (caution: used by partners)
- [ ] /api/personlog/<ext> en els casos de fallada returnar una llista buida sense errors (no son de fallada, encara no hi ha logs i prou)
Expand Down
1 change: 0 additions & 1 deletion b2bdata/inputs/config-2days2lines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,6 @@ websocket_port: 4445
call_reasons_document: "Trucades_3354"
credential_name: "drive-certificate.json"
threshold_hits: 21
my_calls_log: "my_calls_log.yaml"
busyFiles:
- b2bdata/inputs/indisponibilitats-2days2lines.conf

1 change: 0 additions & 1 deletion b2bdata/inputs/config-3days6lines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ websocket_port: 4445
call_reasons_document: "Trucades_3354"
credential_name: "drive-certificate.json"
threshold_hits: 21
my_calls_log: "my_calls_log.yaml"
busyFiles:
- b2bdata/inputs/indisponibilitats-3days6lines.conf

1 change: 0 additions & 1 deletion b2bdata/inputs/config-4days6lines.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,6 @@ websocket_port: 4445
call_reasons_document: "Trucades_3354"
credential_name: "drive-certificate.json"
threshold_hits: 21
my_calls_log: "my_calls_log.yaml"
busyFiles:
- b2bdata/inputs/indisponibilitats.conf
- b2bdata/inputs/indisponibilitats-vacances.conf
Expand Down
1 change: 0 additions & 1 deletion b2bdata/inputs/load-2020-03-02/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,3 @@ websocket_port: 4445
call_reasons_document: Trucades_3354
credential_name: drive-certificate.json
threshold_hits: 21
my_calls_log: my_calls_log.yaml
1 change: 0 additions & 1 deletion b2bdata/inputs/load-and-schedule-2-days/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,3 @@ forced: {}
call_reasons_document: Trucades_3354
credential_name: drive-certificate.json
threshold_hits: 21
my_calls_log: callinfo/dailycalls.yaml
2 changes: 1 addition & 1 deletion config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,4 @@ commented_forced:
call_reasons_document: Trucades_3354
credential_name: drive-certificate.json
threshold_hits: 21
my_calls_log: callinfo/dailycalls.yaml
callinfoPath: callinfo
13 changes: 9 additions & 4 deletions doc/development.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ What smoke tests you should be doing after an upgrade to check most components s
- `execution.py`: Encapsulates an asynchronous execution of a sandboxed process (used by `planner_api.py`)
- `remote.py`: Simplifies remote process execution and access to files via SSH
- `directmessage`: modules that abstract actual direct message (hangouts or equivalents)
- `directmessage/hangouts`: Google hangouts implementation of directmessage
- `directmessage/hangouts.py`: Google hangouts implementation of directmessage
- `backchannel.py`: Abstracting server initiated comunication with the clients (Websocket or equivalent)

### Information Access
Expand All @@ -129,9 +129,10 @@ What smoke tests you should be doing after an upgrade to check most components s
- `claims.py`: Access the ERP's Claim objects (Backend of callregistry)


## Data Files
## Callinfo Data Files

This is a review of the callinfo files.
Callinfo data directory is `callinfo/` by default
but can be configured using `callinfoPath` in `config.yaml`.

- `callinfo/categories.yaml`
- Categories to choose when annotating calls
Expand All @@ -140,7 +141,11 @@ This is a review of the callinfo files.
- Each category has `code`, `name`, `isClaim`, `section`
- `callinfo/dailycalls.yaml`
- "registre de trucades (reclamació i no reclamacio)"
- `config.my_calls_log`
- person dict to a list of incomming calls of the day
- `callinfo/cases/YYYY-MM-DD.yaml` Daily call log

## Scheduler Data Files

TODO: Document which files are readed, which ones are generated and how configuration and commandline affects them


19 changes: 10 additions & 9 deletions tomatic/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,13 @@ async def notifyIncommingCall(phone: str, extension: str):
user = persons.byExtension(extension)
phone = phone.replace('+','').replace('-','').replace(' ','')
phone = re.sub(r'^[+]?0?0?34','', phone)
CallRegistry().updateCall(extension, fields=ns(
data = time,
telefon = phone,
motius = "",
partner = "",
contracte = "",
CallRegistry().annotateCall(ns(
user = user,
date = time,
phone = phone,
partner = '',
contract = '',
reason = '',
))
notifications = backchannel.notifyIncommingCall(user, phone, time)
if not notifications:
Expand All @@ -449,9 +450,9 @@ async def notifyIncommingCall(phone: str, extension: str):
return yamlfy(result='ok')


@app.get('/api/personlog/{extension}')
def getCallLog(extension):
calls = CallRegistry().callsByExtension(extension)
@app.get('/api/personlog/{user}')
def getCallLog(user):
calls = CallRegistry().callsByUser(user)
return yamlfy(
info=ns(
info=calls,
Expand Down
65 changes: 36 additions & 29 deletions tomatic/callregistry.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,57 +13,64 @@ def fillConfigurationInfo():

class CallRegistry(object):
def __init__(self, path=None, size=20):
self.path = Path(path or CONFIG.my_calls_log)
self.path.parent.mkdir(parents=True, exist_ok=True)
self.path = Path(path or CONFIG.callinfoPath)
self.path.mkdir(parents=True, exist_ok=True)
self.callregistry_path = self.path / 'dailycalls.yaml'
self.size = size

def _calls(self):
if not self.path.exists():
return ns()
return ns.load(self.path)
def _calls(self, user):
callregistry = self.path / f'dailycalls-{user}.yaml'
if not callregistry.exists():
return ns(calls=[])
return ns.load(callregistry)

def callsByExtension(self, extension):
return self._calls().get(extension,[])

def updateCall(self, extension, fields):
calls = self._calls()
extensionCalls = calls.setdefault(extension,[])
for call in extensionCalls:
if call.data == fields.data:
def callsByUser(self, user):
return self._calls(user).calls

def updateCall(self, user, fields):
calls = self.callsByUser(user)
callregistry = self.path / f'dailycalls-{user}.yaml'

for call in calls:
if call.date == fields.date:
call.update(fields)
break
else: # exiting when not found
extensionCalls.append(fields)
else: # for else, not typo, when not break
calls.append(fields)

if self.size:
extensionCalls=extensionCalls[-self.size:]
del calls[:-self.size]

calls.dump(self.path)
ns(calls=calls).dump(callregistry)

def annotateCall(self, fields):
from . import persons
extension = persons.extension(fields.user) or fields.user
self.updateCall(extension, ns(
data = fields.date,
telefon = fields.phone,
partner = fields.partner,
contracte = fields.contract,
motius = fields.reason,
self.updateCall(fields.user, ns(
(key, value)
for key, value in fields.items()
if key != 'user' # TODO: To keep the same behavior. Is this needed?
))
self._appendToExtensionDailyInfo('cases', fields)

def _appendToExtensionDailyInfo(self, prefix, info, date=datetime.today()):
path = self.path.parent / prefix / '{:%Y%m%d}.yaml'.format(date)
path = self.path / prefix / '{:%Y%m%d}.yaml'.format(date)
warn("Saving {}", path)
dailyInfo = ns()
if path.exists():
dailyInfo = ns.load(str(path))
dailyInfo.setdefault(info.user, []).append(info)
userInfo = dailyInfo.setdefault(info.user, [])
for call in userInfo:
if call.date == info.date:
call.update(info)
break
else:
userInfo.append(info)
path.parent.mkdir(parents=True, exist_ok=True)
dailyInfo.dump(str(path))

def _categoriesFile(self):
return self.path.parent/'categories.yaml'
return self.path/'categories.yaml'

def updateAnnotationCategories(self, erp):
"""Takes the topics (crm categories and atc subtypes)"""
Expand All @@ -89,8 +96,8 @@ def annotationCategories(self):

def uploadCases(self, erp, date):
claims = Claims(erp)
path = self.path.parent / 'cases' / '{:%Y%m%d}.yaml'.format(date)
log = self.path.parent / 'cases' / 'logs' / '{:%Y%m%d}.log'.format(date)
path = self.path / 'cases' / '{:%Y%m%d}.yaml'.format(date)
log = self.path / 'cases' / 'logs' / '{:%Y%m%d}.log'.format(date)
cases = ns()
if path.exists():
cases = ns.load(path)
Expand Down
Loading

0 comments on commit 69bbcfc

Please sign in to comment.