1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

「目が悪いから前の方!!」に応える、席替えプログラムを作ってPyPIに公開した。

Last updated at Posted at 2019-09-12

2019/09/13追記 パイプラインに対応
#Pipeline


sekigae

というパッケージ名で席替えするPythonプログラムを作りました。
https://github.com/kamuiroeru/sekigae

特徴としては

があって、3つめは結構使える機能だと思います。

Install

python3系を導入済みの方は

pip install sekigae

で使えます。
※(globalなコマンドとして sekigae)がインストールされるので注意

使い方

シンプルな使い方

13 人を 5 列で作成

sekigae 13 5
output
          FRONT           
--------------------------
| 10 |  7 |  3 |  5 |  2 |
--------------------------
|  4 | 11 | 12 |  1 |  6 |
--------------------------
|  8 | 13 |  9 |

上のラベルを変更

黒板 に変更

sekigae 13 5 -t 黒板
output
            黒板            
--------------------------
|  2 |  9 |  5 | 11 |  1 |
--------------------------
| 10 |  7 | 12 |  8 |  6 |
--------------------------
| 13 |  3 |  4 |

CSVに書き出し

test.csv に書き出す

sekigae 13 5 -o test.csv
output
          FRONT           
--------------------------
| 12 | 11 |  7 |  5 |  3 |
--------------------------
|  9 |  1 |  4 |  6 | 10 |
--------------------------
| 13 |  2 |  8 |
csv wrote
test.csv
12,11,7,5,3
9,1,4,6,10
13,2,8

CSVを読み込む

test.csv を読み込む
※人数と列数の指定は必須ですが、無視されます。

test.csv
12,11,7,5,3
9,1,4,6,10
13,2,8
sekigae 45 6 --csv test.csv
output
          FRONT           
--------------------------
| 12 | 11 |  7 |  5 |  3 |
--------------------------
|  9 |  1 |  4 |  6 | 10 |
--------------------------
| 13 |  2 |  8 |

任意の場所に誰かを固定

「7番の人は目が悪いから一番前!!」
「9番の人は前に行きたいって!!」
という要望に応えます。

  • 7番を 1行3列目に固定
  • 9番を 2行2列目に固定

という指定で作成

sekigae 13 5 -s 1:3:7,2:2:9
output
          FRONT           
--------------------------
|  6 |  8 |  7 |  5 | 11 |
--------------------------
|  1 |  9 |  2 |  3 | 13 |
--------------------------
| 10 | 12 |  4 |

          FRONT           
--------------------------
|  1 |  2 |  7 | 12 | 13 |
--------------------------
| 11 |  9 |  5 | 10 |  3 |
--------------------------
|  4 |  6 |  8 |

          FRONT           
--------------------------
| 12 | 13 |  7 |  1 |  5 |
--------------------------
|  4 |  9 |  2 |  8 |  6 |
--------------------------
| 11 |  3 | 10 |

常に
7番は1行3列目
9番は2行2列目

Pipeline

Pipeline input

cat コマンドとかのパイプ入力に対応

out.csv
10,12,3,5,6
11,4,9,1,13
7,8,2
shell
cat out.csv | sekigae
output
          FRONT
--------------------------
| 10 | 12 |  3 |  5 |  6 |
--------------------------
| 11 |  4 |  9 |  1 | 13 |
--------------------------
|  7 |  8 |  2 |

Pipeline output

-f で CSV形式で表示するようにした。
awkとか色々組み合わせられる。

shell
sekigae 13 5 -f | awk '{ if (gsub(/,/, " ")) print }'
output
8 5 7 10 12
11 6 3 4 1
13 2 9

P.S.

初めてPyPIに登録したのですが、自分の作った機能が pip install で使えるってのは良いもんですね〜

1
0
4

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?