<commit_before>" Web URLs {{{
let g:analog#web#base_url = 'https://analogio.dk/publicshiftplanning/api/%s/analog'
let g:analog#web#open_url = printf(g:analog#web#base_url, 'open')
let g:analog#web#shifts_url = printf(g:analog#web#base_url, 'shifts')
let g:analog#web#shifts_today_url = printf(g:analog#web#base_url, 'shifts/today')
" }}}

" General {{{
function! analog#version()
    return g:analog#version
endfunction

function! analog#is_open()
    let json = analog#web#request(g:analog#web#open_url, '')

    if empty(json)
        return -1
    endif

    return analog#json#parse_open_status(json)
endfunction

function! analog#is_open_or_echoerr()
    let state = analog#is_open()

    if state == 0
        if g:analog#ignore_closed
            return 1
        endif

        call analog#warn("Analog is closed")
    elseif state == -1
        call analog#warn("No connection, or service is unavailable")
    endif

    return state
endfunction

function! analog#get_staff()
    let json = analog#web#request(g:analog#web#shifts_url, '')

    return analog#json#parse_json_employees(json)
endfunction

function! analog#get_current_staff()
    let json = analog#web#request(g:analog#web#shifts_url, '')
    let staff = analog#json#parse_json_employees(json)
    let hours = analog#json#parse_json_open_hours(json)
    let i = analog#time#in_interval(split(strftime('%H:%M'), ':'), hours)

    return (i == -1 ? [] : staff[i])
endfunction

function! analog#get_open_hours()
    let json = analog#web#request(g:analog#web#shifts_url, '')

    return analog#json#parse_json_open_hours(json)
endfunction

function! analog#get_all_matches(str, pattern)
    let results = []
    call substitute(a:str, a:pattern, '\=add(results, submatch(0))', 'g')

    return results
endfunction

function! analog#get_current_symbol()
    return [g:analog#no_coffee_symbol, g:analog#coffee_symbol, g:analog#no_connection_symbol][analog#is_open()]
endfunction

function! analog#warn(msg)
    echohl WarningMsg
    echo "vim-analog: " . a:msg
    echohl NONE
endfunction
" }}}

" Echo status {{{
" Yes: DiffAdd, No: WarningMsg
function! analog#echo_open_status()
    echo analog#get_current_symbol()
endfunction

function! analog#echo_staff()
    if analog#is_open_or_echoerr() > 0
        let staff = analog#get_staff()

        if empty(staff)
            call analog#warn("No staff, Analog is closed")
            return
        endif

        let hours = analog#get_open_hours()
        
        for i in range(0, len(staff) - 1)
            let s = join(staff[i], ', ')
            let from = hours[i * 2]
            let to = hours[i * 2 + 1]

            echo printf("%s (%s - %s)", s, from, to)
        endfor
    endif
endfunction

function! analog#echo_current_staff()
    if analog#is_open_or_echoerr() > 0
        let staff = analog#get_current_staff()

        if empty(staff)
            call analog#warn("No staff, Analog is closed")
        else
            echo join(staff, ', ')
        endif
    endif
endfunction

function! analog#echo_open_hours()
    if analog#is_open_or_echoerr() > 0
        let hours = analog#get_open_hours()

        if empty(hours)
            call analog#warn("No open hours, Analog is closed")
        else
            for i in range(0, len(hours) - 1, 2)
                echo printf("%s - %s", hours[i], hours[i + 1])
            endfor
        endif
    endif
endfunction

function! analog#echo_time_to_close()
    if analog#is_open_or_echoerr() > 0
        let diff = analog#time#time_to_close()

        if empty(diff)
            call analog#warn("Analog is closed")
        else
            if diff[0] < 0 || diff[1] < 0
                echo printf("Analog closed %s hour(s) and %s minute(s) ago", diff[0], diff[1])
            else
                echo printf("Analog closes in %s hour(s) and %s minute(s)", diff[0], diff[1])
            endif<commit_msg>Short documentation strings for all autoload functions<commit_after>" Web URLs {{{
let g:analog#web#base_url = 'https://analogio.dk/publicshiftplanning/api/%s/analog'
let g:analog#web#open_url = printf(g:analog#web#base_url, 'open')
let g:analog#web#shifts_url = printf(g:analog#web#base_url, 'shifts')
let g:analog#web#shifts_today_url = printf(g:analog#web#base_url, 'shifts/today')
" }}}

" Queries {{{
" Return the current version of vim-analog
function! analog#version()
    return g:analog#version
endfunction

" Return 1 if Analog is open, 0 if closed or -1 if a problem
" occured such as missing or malformed data
function! analog#is_open()
    let json = analog#web#request(g:analog#web#open_url, '')

    if empty(json)
        return -1
    endif

    return analog#json#parse_open_status(json)
endfunction

" Check if Analog is open or warn the user
function! analog#is_open_or_echoerr()
    let state = analog#is_open()

    if state == 0
        if g:analog#ignore_closed
            return 1
        endif

        call analog#warn("Analog is closed")
    elseif state == -1
        call analog#warn("No connection, or service is unavailable")
    endif

    return state
endfunction

" Get a list of names of the staff working at Analog today
function! analog#get_staff()
    let json = analog#web#request(g:analog#web#shifts_url, '')

    return analog#json#parse_json_employees(json)
endfunction

" Get a list of names of the staff working at Analog right now
function! analog#get_current_staff()
    let json = analog#web#request(g:analog#web#shifts_url, '')
    let staff = analog#json#parse_json_employees(json)
    let hours = analog#json#parse_json_open_hours(json)
    let i = analog#time#in_interval(split(strftime('%H:%M'), ':'), hours)

    return (i == -1 ? [] : staff[i])
endfunction

" Get today's opening hours of Analog as a 2 element list of the opening
" and closing time
function! analog#get_open_hours()
    let json = analog#web#request(g:analog#web#shifts_url, '')

    return analog#json#parse_json_open_hours(json)
endfunction

" Collect all regex matches in a string and return them in a list
function! analog#get_all_matches(str, pattern)
    let results = []
    call substitute(a:str, a:pattern, '\=add(results, submatch(0))', 'g')

    return results
endfunction

" Return the symbol for Analog's current open status
function! analog#get_current_symbol()
    return [g:analog#no_coffee_symbol, g:analog#coffee_symbol, g:analog#no_connection_symbol][analog#is_open()]
endfunction

" Issue a highlighted warning message
function! analog#warn(msg)
    echohl WarningMsg
    echo "vim-analog: " . a:msg
    echohl NONE
endfunction
" }}}

" Echo status {{{
" Yes: DiffAdd, No: WarningMsg
function! analog#echo_open_status()
    echo analog#get_current_symbol()
endfunction

" Echo the staff working in Analog today along with opening hours

        let hours = analog#get_open_hours()
        
        for i in range(0, len(staff) - 1)
            let s = join(staff[i], ', ')
            let from = hours[i * 2]
            let to = hours[i * 2 + 1]

            echo printf("%s (%s - %s)", s, from, to)
        endfor
    endif
endfunction

" Echo Analog's current staff
function! analog#echo_current_staff()
    if analog#is_open_or_echoerr() > 0
        let staff = analog#get_current_staff()

        if empty(staff)
            call analog#warn("No staff, Analog is closed")
        else
            echo join(staff, ', ')
        endif
    endif
endfunction

" Echo Analog's opening hours
function! analog#echo_open_hours()
    if analog#is_open_or_echoerr() > 0
        let hours = analog#get_open_hours()

        if empty(hours)
            call analog#warn("No open hours, Analog is closed")
        else
            for i in range(0, len(hours) - 1, 2)
                echo printf("%s - %s", hours[i], hours[i + 1])
            endfor
        endif
    endif
endfunction

" Echo the remaining time that Analog is open
function! analog#echo_time_to_close()
    if analog#is_open_or_echoerr() > 0
        let diff = analog#time#time_to_close()

        if empty(diff)
            call analog#warn("Analog is closed")
        else
            if diff[0] < 0 || diff[1] < 0
                echo printf("Analog closed %s hour(s) and %s minute(s) ago", diff[0], diff[1])
            else
                echo printf("Analog closes in %s hour(s) and %s minute(s)", diff[0], diff[1])
            endif
{'fraction_non_alphanumeric': 0.11438848920863309, 'fraction_numerical': 0.006834532374100719, 'mean_word_length': 3.1374007936507935, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 10, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1733553', 'n_tokens_mistral': 2817, 'n_tokens_neox': 2647, 'n_words': 710}