python-visualization / python-visualization/folium

FeatureGroupSubGroup: nth level subgroups

未关闭
#1,758 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

More info needed
主要语言
Python
星标
7.4k
派生
2.3k
平均合并
17 小时 22 分钟
30 天内合并 PR
11

描述

Describe the bug
I am using quite a few levels of recursion to generate a map that has subgroups within subgroups, and im not sure how to fix the issue, or if there is a better method.

To Reproduce
theres alot going on here... the repeated for loops are to keep the buttons ordered by hierarchy.

import folium
from folium import plugins

#####################################################################################
coord = df['Location'].apply(fetch_lat_lon)
df['Lat'] = coord.apply(lambda x: x[0] if isinstance(x, tuple) else None)
df['Long'] = coord.apply(lambda x: x[1] if isinstance(x, tuple) else None)

df['Result'] = (~df['Impounded'].isna().astype(int)).apply(lambda x: _results[x])
df['Interval'] = (datetime.now() - df.index).days
df['Weekday'] = df.index.weekday.map(lambda x: _days[x])
df['Time'] = df.index.hour

df = df[~df['ID'].isna()]                                                           
#####################################################################################
m = folium.Map(location=[0, 0], zoom_start=14)


results = {}
intervals = {}
days = {}
times = {}

_results = ['Complete', 'Canceled']
_intervals = [7, 30, 90, 365] ## days before now
_days = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday']
_times = range(24)

for result in _results:

    results[result] = folium.FeatureGroup(name = result)
    m.add_child(results[result])

for result in _results:
    for interval in _intervals: 

        intervals[f'{result}_{interval}'] = plugins.FeatureGroupSubGroup(results[result], f'{interval} Days')
        m.add_child(intervals[f'{result}_{interval}'])

for result in _results:
    for interval in _intervals: ## days before now
        for day in _days:

            days[f'{result}_{interval}_{day}'] = plugins.FeatureGroupSubGroup(intervals[f'{result}_{interval}'], day)
            m.add_child(days[f'{result}_{interval}_{day}'])

for result in _results:
    for interval in _intervals: ## days before now
        for day in _days:
            for time in _times:
                
                if time < 12:
                    if time !=0:
                        times[f'{result}_{interval}_{day}_{time}'] = plugins.FeatureGroupSubGroup(days[f'{result}_{interval}_{day}'], f'{time} AM')
                        m.add_child(times[f'{result}_{interval}_{day}_{time}'])
                    else: 
                        times[f'{result}_{interval}_{day}_{time}'] = plugins.FeatureGroupSubGroup(days[f'{result}_{interval}_{day}'], f'{time + 12} AM')
                        m.add_child(times[f'{result}_{interval}_{day}_{time}'])
                elif time > 12:
                    times[f'{result}_{interval}_{day}_{time}'] = plugins.FeatureGroupSubGroup(days[f'{result}_{interval}_{day}'], f'{time - 12} PM')
                    m.add_child(times[f'{result}_{interval}_{day}_{time}'])
                else:
                    times[f'{result}_{interval}_{day}_{time}'] = plugins.FeatureGroupSubGroup(days[f'{result}_{interval}_{day}'], f'{time} PM')
                    m.add_child(times[f'{result}_{interval}_{day}_{time}'])

for result in _results:
    for interval in _intervals: ## days before now
        for day in _days:
            for time in _times:

                group = times[f'{result}_{interval}_{day}_{time}']

                condition = ((df['Result'] == result) &
                             (df['Interval'] <= interval) &
                             (df['Weekday'] == day) &
                             (df['Time'] == time)
                )

                _df = df[condition].dropna()

                for i in range(len(_df)):
                    lat = _df['Lat'].iloc[i] - _df['Lat'].mean()
                    long = _df['Long'].iloc[i] - _df['Long'].mean()

                    folium.Marker([lat, long]).add_to(group)
            
folium.LayerControl(collapsed=True).add_to(m)

m.save('TESTING.html')

Expected behavior
When all button conditions are met, points will display,

Environment (please complete the following information):

  • chrome
  • jupyter notebooks
  • vs code

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从提供的 FeatureGroupSubGroup 构造和 Jupyter/VS Code 复现中生成的 TESTING.html 开始;验证超过一层的嵌套子组是否按预期表示和切换。定义所需的第 n 级行为,并使用最小地图复现进行确认,包括所述的点显示条件。

由索引模型根据 Issue 内容生成。

评估

技术栈
jupyter-notebook, python
领域
data-visualization
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
需要澄清
新手友好度
25/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。